-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac_changer.py
46 lines (31 loc) · 1.3 KB
/
mac_changer.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
import subprocess
import optparse
import re
def get_args():
parser = optparse.OptionParser()
parser.add_option("-i","--interface",dest="interface",help="To select an interface")
parser.add_option("-m","--mac",dest="mac",help="Set MAC address of an interface")
(value,arg) = parser.parse_args()
if not value.interface or not value.mac:
print("[-] please specifiy options properly ,use --help for info")
else:
return value
def change_mac(interface,mac):
print("[+] Changing MAC for "+interface+" To"+" "+mac)
subprocess.call(["ifconfig",interface,"down"])
subprocess.call(["ifconfig",interface,"hw","ether",mac])
subprocess.call(["ifconfig",interface,"up"])
def current_mac(interface):
ifconfig_result = subprocess.check_output(["ifconfig",values.interface])
search_mac = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",ifconfig_result)
if search_mac:
return search_mac.group(0)
else:
print("[-] Cannot Find MAC Address ")
values = get_args()
curr_mac = current_mac(values.interface)
print("[+] Current MAC Address is : "+str(curr_mac))
change_mac(values.interface,values.mac)
curr_mac = current_mac(values.interface)
if curr_mac == values.mac:
print("[+] Mac address successfully changed to : "+str(curr_mac))