-
Notifications
You must be signed in to change notification settings - Fork 1
/
change-mac.py
43 lines (33 loc) · 1.38 KB
/
change-mac.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
import subprocess
import optparse
import re
def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i","--interface",dest="interface",help="enter interface")
parser.add_option("-m","--mac",dest="new_mac",help="enter new mac")
(options,arguments) = parser.parse_args();
if not options.interface:
parser.error('[-] invalid interface')
if not options.new_mac:
parser.error('[-] invalid mac')
return options;
def mac_changer(interface,newMac):
subprocess.call(["ifconfig",interface,"down"])
subprocess.call(["ifconfig",interface ,"hw","ether",newMac])
subprocess.call(["ifconfig",interface ,"up"])
def get_current_mac(interface):
if_config_result = subprocess.check_output(["ifconfig",interface])
reg_exp_match = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",if_config_result.decode('utf-8'))
if reg_exp_match:
return reg_exp_match.group(0)
else:
print("[-] we could not read the current mac address of "+ interface)
options = get_arguments();
current_mac = get_current_mac(options.interface)
print("[+] current mac is "+ str(current_mac))
mac_changer(options.interface,options.new_mac)
current_mac = get_current_mac(options.interface)
if current_mac == options.new_mac:
print("[+]current mac is successfully changed to "+ options.new_mac)
else:
print("[+]current mac could not be changed")