Skip to content

Commit 1ac1f91

Browse files
authored
Mac Changer v2
Mac Changer v2
1 parent 82cbc98 commit 1ac1f91

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Mac changer/Mac Changer v2.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env/ python
2+
import subprocess
3+
import optparse
4+
import re
5+
6+
def get_args():
7+
parser = optparse.OptionParser()
8+
parser.add_option("-i", "--interface",dest="interface",help="interface to change its MAC address")
9+
parser.add_option("-m", "--mac",dest="new_MAC",help="New Mac address")
10+
(options,arguments) = parser.parse_args()
11+
if not options.interface:
12+
#code to handle errors
13+
parser.error("[-] Please specify an interface use --help for more info.")
14+
elif not options.new_MAC:
15+
#code to handle errors
16+
parser.error("[-] Please specify an mac use --help for more info.")
17+
return options
18+
19+
def change_mac(interface,new_mac):
20+
print("[+] Changeing MAC address for "+ interface + " to "+ new_mac)
21+
subprocess.call(["ifconfig" , interface , "down"])
22+
subprocess.call(["ifconfig" , interface , "hw","ether",new_mac])
23+
subprocess.call(["ifconfig" , interface , "up"])
24+
25+
def get_current_mac(interface):
26+
ifconfig_result = subprocess.check_output(["ifconfig",interface]).decode('utf-8')
27+
mac_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",ifconfig_result)
28+
if mac_search_result:
29+
return mac_search_result.group(0)
30+
else:
31+
print("[-] Sorry could not read MAC address.")
32+
#Gets args from commandline
33+
options = get_args()
34+
current_mac = get_current_mac(options.interface)
35+
print("[-] Current Mac: "+ str(current_mac))
36+
37+
change_mac(options.interface,options.new_MAC)
38+
current_mac = get_current_mac(options.interface)
39+
if current_mac == options.new_MAC:
40+
print("[+] MAC address was succesfuly changed to "+ options.new_MAC)
41+
else:
42+
print("[-] MAC address couldnt be changed")
43+
print("[-] According to standerds MAC should start with and even pair")
44+
45+
# v2 no secureity implemented you can execute commands
46+
# subprocess.call("ifconfig " + interface +" down" ,shell=True)
47+
# subprocess.call("ifconfig "+ interface +" hw ether "+ new_MAC ,shell=True)
48+
# subprocess.call("ifconfig "+ interface +" up",shell=True)
49+
50+
51+
# v1
52+
# subprocess.call("ifconfig wlan0 down",shell=True)
53+
# subprocess.call("ifconfig wlan0 hw ether 00:11:22:33:44:55:66",shell=True)
54+
# subprocess.call("ifconfig wlan0 up",shell=True)

0 commit comments

Comments
 (0)