-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMac_Changer.py
More file actions
39 lines (28 loc) · 1.16 KB
/
Mac_Changer.py
File metadata and controls
39 lines (28 loc) · 1.16 KB
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
import subprocess
import optparse
import re
def get_user_input():
parse_object = optparse.OptionParser()
parse_object.add_option("-i","--interface",dest="interface",help="interface to change!")
parse_object.add_option("-m","--mac",dest="mac_address",help="new mac address")
return parse_object.parse_args()
def change_mac_address(user_interface,user_mac_address):
subprocess.call(["ifconfig",user_interface,"down"])
subprocess.call(["ifconfig",user_interface,"hw","ether",user_mac_address])
subprocess.call(["ifconfig",user_interface,"up"])
def control_new_mac(interface):
ifconfig =subprocess.check_output(["ifconfig",interface])
new_mac=re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",ifconfig)
if new_mac:
return new_mac.group(0)
else:
return None
#python MacChanger.py -i eth0 -m 00:11:22:33:44:55
print("MyMacChanger started!")
(user_input,arguments) =get_user_input()
change_mac_address(user_input.interface,user_input.mac_address)
finalized_mac =control_new_mac(user_input.interface)
if finalized_mac == user_input.mac_address:
print("Success")
else:
print("Error!")