Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import subprocess
  4. import optparse
  5. import re
  6.  
  7.  
  8. def get_arguments():
  9. parser = optparse.OptionParser()
  10. parser.add_option("-i", "--interface", dest="interface", help="Interface to change MAC address")
  11. parser.add_option("-m", "--mac", dest="new_mac", help="New MAC address")
  12. (options, arguments) = parser.parse_args()
  13. if not options.interface:
  14. parser.error("[-] Please specify an interface, use --help for more info.")
  15. elif not options.new_mac:
  16. parser.error("[-] Please specify a new MAC, use --help for more info.")
  17. return options
  18.  
  19.  
  20. def change_mac(interface, new_mac):
  21. subprocess.call(["ifconfig", interface, "down"])
  22. subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
  23. subprocess.call(["ifconfig", interface, "up"])
  24. print("[+] Changed MAC address for " + interface + " to " + new_mac)
  25.  
  26.  
  27. options = get_arguments()
  28. # change_mac(options.interface, options.new_mac)
  29.  
  30. ifconfig_result = subprocess.check_output(["ifconfig", options.interface])
  31. print(ifconfig_result)
  32.  
  33. pattern = re.compile(r'([0-9a-f]{2}(?::[0-9a-f]{2}){5})', re.IGNORECASE)
  34. mac_address_search_result = re.findall(p, ifconfig_result)
  35.  
  36. if mac_address_search_result:
  37. print(mac_address_search_result.group(0))
  38. else:
  39. print("[-] Could not read MAC address")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement