-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacchanger.py
37 lines (33 loc) · 1.38 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
import subprocess
import optparse
import re
def get_arguments():
parser=optparse.OptionParser()
parser.add_option("-i","--interface",dest="interface",help="add interface")
parser.add_option("-m","--mac",dest="new_mac",help="add new mac")
(options,arguments)=parser.parse_args()
if not options.interface:
parser.error("Please specify interface or type --help for more info")
elif not options.new_mac:
parser.error("Please supply new MAC address or type --help for more info")
return options
def get_current_mac(interface):
ifconfig_result=str(subprocess.check_output(["ifconfig",interface]))
ifconfig_search_result=re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",ifconfig_result)
if ifconfig_result:
return ifconfig_search_result.group(0)
else:
print("[-]Could not read MAC address")
def change_mac(interface,new_mac):
subprocess.call(["ifconfig",interface,"down"])
subprocess.call(["ifconfig",interface,"hw","ether",new_mac])
subprocess.call(["ifconfig",interface,"up"])
options=get_arguments()
current_mac=get_current_mac(options.interface)
print("Current MAC= "+str(current_mac))
change_mac(options.interface,options.new_mac)
current_mac=get_current_mac(options.interface)
if current_mac==options.new_mac:
print("[+]MAC Address was succesfully changed to ",current_mac)
else:
print("[-]MAC did not change successfully.")