Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env python
- 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 Interface use --help for more info. ")
- elif not options.new_mac:
- parser.error("[-] Please specify new MAC use --help for more info. ")
- return options
- return parser.parse_args()
- def change_mac(interface,new_mac):
- print("[+] 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_result = subprocess.check_output(["ifconfig", interface])
- mac_address_search_results = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", str(ifconfig_result))
- if mac_address_search_results:
- return mac_address_search_results.group(0)
- else:
- print("[-] Could not read MAC address ")
- options = get_arguments()
- current_mac = get_current_mac(options.interface)
- print("Current MAC = " + str(current_mac))
- change_mac(options.interface, options.new_mac)
- current_mac = get_current_mac(options.interface)
- if current_mac ==options.new_mac:
- print("[+] MAC address was changed to " + current_mac)
- else:
- print("[-] MAC address did not change")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement