- This topic has 15 replies, 2 voices, and was last updated 3 years, 5 months ago by Diego Pérez.
- AuthorPosts
- June 8, 2021 at 10:19 pm #55595pranetkulParticipant
Hi Sir, I have a problem with this code as I receive this: RuntimeError: maximum recursion depth exceeded while calling a Python object
Can you let me know please what is wrong with my code?
#!/usr/bin/env python import re import subprocess import optparse def get_args(): parser = optparse.OptionParser() parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address") parser.add_option("-m", "--mac", dest="interface", help="New mac address") (options, arguments) = get_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): 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) print(ifconfig_result) mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", str(ifconfig_result)) if mac_address_search_result: return mac_address_search_result.group(0) else: print("[-] Could not read MAC address.") options = get_args() 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 successfully changed to " + current_mac) else: print("[-] MAC address did not get changed")
June 9, 2021 at 6:07 pm #55627Diego PérezModeratorHi!
Can you share a screenshot with the command used to run the code and the result please?
Thanks!
DiegoJune 9, 2021 at 10:43 pm #55631pranetkulParticipantfile:///root/Pictures/Screenshot%20from%202021-06-09%2022-41-11.png
file:///root/Pictures/Screenshot%20from%202021-06-09%2022-41-16.png
June 9, 2021 at 10:44 pm #55632pranetkulParticipantSorry if you can’t see the image. I cannot figure out how to send them
June 10, 2021 at 6:13 pm #55649Diego PérezModeratorHi!
Just upload them to some image hosting service or Gdrive and share the link here.
Greetings!
DiegoJune 10, 2021 at 9:12 pm #55660pranetkulParticipantJune 10, 2021 at 9:13 pm #55661June 10, 2021 at 9:17 pm #55662pranetkulParticipantJune 11, 2021 at 7:10 pm #55684Diego PérezModeratorHi!
The access is restricted, can you allow it to anyone who has the link?Thanks!
DiegoJune 11, 2021 at 7:38 pm #55686June 12, 2021 at 3:30 pm #55708pranetkulParticipantHopefully, the images work now
June 12, 2021 at 5:45 pm #55713Diego PérezModeratorHi!
In the get_args function you have used interface as dest value for both options, correct this and try it again.
Greetings!
DiegoJune 13, 2021 at 4:09 pm #55725pranetkulParticipant#!/usr/bin/env python import re import subprocess import optparse def get_args(): 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) = get_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): 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) print(ifconfig_result) mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", str(ifconfig_result)) if mac_address_search_result: return mac_address_search_result.group(0) else: print("[-] Could not read MAC address.") options = get_args() 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 successfully changed to " + current_mac) else: print("[-] MAC address did not get changed")
June 13, 2021 at 4:10 pm #55726pranetkulParticipantimg1
https://drive.google.com/file/d/1PiVxpWo3JIqQpZMF81ivlA_Qs29DLmac/view?usp=sharing
I still get error when I change the codeJune 14, 2021 at 4:16 pm #55745pranetkulParticipantcan you let me know please what I should do
- AuthorPosts
- You must be logged in to reply to this topic.