ayush2003


SUBMITTED BY: ayush2003

DATE: Jan. 13, 2021, 5:36 p.m.

FORMAT: Python 3.0 Traceback

SIZE: 1.4 kB

HITS: 120

  1. import subprocess
  2. import optparse
  3. import re
  4. def add_value ():
  5. pharse=optparse.OptionParser()
  6. pharse.add_option("-i","--interface", dest="interface",help="Indicate a Interface")
  7. pharse.add_option("-m","--mac",dest="mac", help="new MAC address ")
  8. (options,arguments)= pharse.parse_args()
  9. if not options.interface:
  10. pharse.error("[-] Cannot find any interface to work on" )
  11. elif not options.mac:
  12. pharse.error("[-] Suggest a mac adress to be changed")
  13. def change_mac (interface,mac):
  14. print("[-] Changing MAC adress of"+interface+"to"+mac)
  15. subprocess.call(["ifconfig",interface,"down"])
  16. subprocess.call(["ifconfig",interface,"hw", "ether",mac])
  17. subprocess.call(["ifconfig",interface,"up"])
  18. def check_stats(interface):
  19. changed_mac= subprocess.check_output("ifconfig",interface)
  20. ifconfig_check= re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",changed_mac)
  21. if ifconfig_check:
  22. return ifconfig_check.group(0)
  23. else:
  24. print("[-] Could not print mac adress of"+ interface)
  25. options= add_value()
  26. old_mac=check_stats(options.interface)
  27. print(str(old_mac))
  28. change_mac(options.interface,options.mac)
  29. new_mac =check_stats(options.interface)
  30. if new_mac==options.mac:
  31. print("[+]The MAC address was changed to "+str(new_mac))
  32. else :
  33. print("[-]Mac address was not changed")

comments powered by Disqus