Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import subprocess
- import optparse
- import re
- def get_arguments():
- parser = optparse.OptionParser()
- parser.add_option("-i", "--interface", dest="interface", help="Interface to change 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 a new MAC, use --help for more info.")
- return options
- def change_mac(interface, new_mac):
- subprocess.call(["ifconfig", interface, "down"])
- subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
- subprocess.call(["ifconfig", interface, "up"])
- print("[+] Changed MAC address for " + interface + " to " + new_mac)
- options = get_arguments()
- # change_mac(options.interface, options.new_mac)
- ifconfig_result = subprocess.check_output(["ifconfig", options.interface])
- print(ifconfig_result)
- pattern = re.compile(r'([0-9a-f]{2}(?::[0-9a-f]{2}){5})', re.IGNORECASE)
- mac_address_search_result = re.findall(pattern, ifconfig_result)
- if mac_address_search_result:
- print(mac_address_search_result.group(0))
- else:
- print("[-] Could not read MAC address")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement