-
Notifications
You must be signed in to change notification settings - Fork 0
/
macchanger.py
63 lines (42 loc) · 1.7 KB
/
macchanger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import subprocess #to invoke system commands
import optparse #parsing command line arguments
import re
def inputparser():#Parsing Command Line arguments
parse=optparse.OptionParser();
parse.add_option("-i","--interface",dest="inter",help="To check Interface use ifconfig or ipconfig. eg eth0,wlan0 etc.")
parse.add_option("-m","--mac",dest="nmac",help="Specify the new mac address that has to be spoofed");
return parse.parse_args();
def check_interface(inter,nmac):
if (inter=="lo"):
print("[-]The Mentioned Interface Doesnt Have any MAC ADDR")
else:
output=subprocess.check_output(["ifconfig"])
output=output.decode('utf-8')
if(re.search(inter,output)):
mac_changer(inter,nmac)
else:
print("[-]Check Your Interface")
def check_change(inter,nmac):
cmd=subprocess.check_output(["ifconfig",inter])
cmd2=cmd.decode('utf-8')
mac_valu=re.findall(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",cmd2)
if (mac_valu[0]==nmac):
print("[+]Change successfull")
else :
print("[-]Error changing Mac , specify Mac in this format XX:XX:XX:XX:XX:XX")
def mac_changer(inter,nmac): # function to change the mac addr
print("[+]Changing Mac Address of "+inter+" to "+nmac);
#Prebuit Commands
subprocess.run(["ifconfig",inter,"down"])
subprocess.run(["ifconfig",inter,"hw","ether",nmac]);
subprocess.run(["ifconfig",inter,"up"])
check_change(inter,nmac);
#storing input
data=inputparser()
inter=data[0].inter
nmac=data[0].nmac;
if (not inter and not nmac):
print("Please Specify Both Interface and Mac")
print("Use -h form more details")
else :
check_interface(inter,nmac)