Question

I am trying to make a mac address spoofer in python for my mac as i find other software to be unnecessary advance/hard to understand. First i want a choicebox asking what device you want to spoof but i can not get the if else statement to work. The point if if coice is the first then input this value elif the choice is the second one input that value. If none of the above, you did somthing wrong. and i am running python 2.7

TlDr; If Else Statement do not work as i want (python 2.7).

Here is the code:

#_._# Mac Changer #_._#
import easygui


msg = "What Device do you want to spoof you're mac addresse?"
title = "SpoofMyMac"
choices = ["en0 (Ethernet)", "en1 (WiFi)"]
choice = easygui.choicebox(msg, title, choices)

#####################################
if choice == choice[0]:             #
    easygui.msgbox("Ethernet")      #
elif choice == choice[1]:           # This is where the problem seems to be.
    easygui.msgbox("Wifi")          #
else:                               #
    easygui.msgbox("chus somthin!") #
#####################################

Now this is just the begining of the code, anyone care to help me out with this if else statement?

In advance Thank you! :)

Was it helpful?

Solution

From what I can see, you just have a typo. You want to index choices, not choice:

if choice == choices[0]:  
    #index choices ^           
    easygui.msgbox("Ethernet")      
elif choice == choices[1]:
    #index choices ^          
    easygui.msgbox("Wifi")          
else:                               
    easygui.msgbox("chus somthin!")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top