Nov-18-2018, 03:06 PM
I'm totally new to Python and have tried to make my first little program that can change a MAC address, but I get this error:
Anyone who can help me here ?
Error:Traceback (most recent call last):
File "/root/PycharmProjects/Mac_Changer_Fun/Mac_Changer_Fun.py", line 24, in <module>
ifconfig_result = subprocess.check_output(["ifconfig", options.interface])
AttributeError: 'tuple' object has no attribute 'interface'
I think that the problem is with the "options", because when I start to write options.i I don't get the option to select options.interface. Somehow it seems that interface is not added to options...I think.Anyone who can help me here ?
#!/usr/bin/env python import subprocess import optparse def get_arguments(): 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") return parser.parse_args() def change_mac(interface, new_mac): print("") print("[+] Changing MAC for " + interface + " to " + new_mac) print("") subprocess.call("ifconfig " + interface + " down", shell=True) subprocess.call("ifconfig " + interface + " hw ether " + new_mac, shell=True) subprocess.call("ifconfig " + interface + " up", shell=True options = get_arguments() ifconfig_result = subprocess.check_output(["ifconfig", options.interface]) print(ifconfig_result)