-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac_changer.py
53 lines (39 loc) · 1.63 KB
/
mac_changer.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
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/ python
import re
import subprocess
import optparse
from pwn import *
def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address")
parser.add_option("-m", "--mac", dest="new_mac", help="New MAC address")
(options, arguments) = parser.parse_args()
if not options.interface:
parser.error("[-] Please specify an interface, use --help for more info")
# elif not options.new_mac:
# parser.error("[-] Please specify new MAC address, use --help for more info")
return options
def change_mac(interface, new_mac):
log.info(f"Changing MAC address for {interface} to {new_mac}")
subprocess.call(["ifconfig", interface, "down"])
subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
subprocess.call(["ifconfig", interface, "up"])
def get_current_mac(interface):
ifconfig_results = subprocess.check_output(["ifconfig", interface])
new_mac_address = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", str(ifconfig_results))
if new_mac_address:
return new_mac_address.group(0)
else:
log.warning("Could not read MAC address.")
options = get_arguments()
interface = options.interface
org_mac = "00:0c:29:7f:05:7d"
new_mac = "00:1b:18:6e:04:6c"
current_mac = get_current_mac(interface)
log.success(str("Current MAC address: " + current_mac))
change_mac(interface, new_mac)
current_mac = get_current_mac(interface)
if current_mac == new_mac:
log.success(str("MAC address was successfully changed to " + current_mac))
else:
log.warning("MAC address did not get changed")