Python Forum

Full Version: AttributeError: 'tuple' object has no attribute 'interface'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:

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)
(options, arg) = get_arguments()
      
print(options.interface)