Repository navigation
Expand file tree
/
Copy pathmacchanger.py
More file actions
43 lines (35 loc) · 1.76 KB
/
Copy pathmacchanger.py
File metadata and controls
43 lines (35 loc) · 1.76 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
40
41
42
43
import subprocess
import optparse
import re
def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i", "--interface", dest="network_interface", help="Network interface for changing the MAC address")
parser.add_option("-m", "--mac", dest="new_mac", help="The new MAC address")
(options, _) = parser.parse_args()
if not options.network_interface:
parser.error("[-] No interface provided. Example: python3 macchanger -i wlan0 (--help for more)")
if not options.new_mac:
parser.error("[-] No MAC address provided. Example: python3 macchanger -m 00:11:22:33:44:55 (--help for more)")
return options
def mac_changer(network_interface, new_mac):
subprocess.call(["sudo", "ifconfig", network_interface, "down"])
subprocess.call(["sudo", "ifconfig", network_interface, "hw", "ether", new_mac])
subprocess.call(["sudo", "ifconfig", network_interface, "up"])
def get_mac(interface):
ifconfig_result = subprocess.check_output(["ifconfig", interface]).decode("utf-8")
mac_address_search_result = re.search(r"(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)", ifconfig_result)
if mac_address_search_result:
return mac_address_search_result.group(0)
else:
return None
options = get_arguments()
mac_changer(options.network_interface, options.new_mac)
mac_address = get_mac(options.network_interface)
if mac_address == options.new_mac:
print("[+] MAC address changed for " + options.network_interface + " to " + options.new_mac)
else:
print("[-] Error! MAC address was not changed or could not be found.")
# def reset():
# subprocess.call("sudo ifconfig wlan0 up")
# subprocess.call("sudo ifconfig wlan0 hw ether $(ethtool -P wlan0 | awk '{print $3}')")
# subprocess.call("sudo ifconfig wlan0 down")