Full disclosure, I am completely new to programming so I apologize in advance. I am working on this python script that will get user input and use that input in certain OS commands (ping, traceroute, whois). It is not complete but here is the script :
#!/usr/bin/python
from os import system
def pingz():
system('ping -c 5 %(ab)s' % locals())
def trace_route():
system('traceroute %(cd)s' % locals())
print("My Web Utility:")
print("____________________\n")
print(" 1)Ping a website/IP Address.\n")
print(" 2)Trace the route to a website/IP Address.\n")
print(" 3)Whois inforation.\n")
choice = raw_input("What would you like to do? \n")
if choice == '1':
ab = raw_input("Please enter the Domain Name/IP Address:\n")
pingz()
elif choice == '2':
cd = raw_input("Please enter the Domain Name/IP Address:\n")
trace_route()
I'm getting two errors on each "choice". So for example if I type 1 I get a prompt asking for the domain name/ip address and when I enter it, the error I get is :
Traceback (most recent call last):
File "./test2.py", line 19, in <module>
pingz()
File "./test2.py", line 6, in pingz
system('ping -c 5 %(ab)s' % locals())
KeyError: 'ab'
And very similar error for choice 2. Is there something wrong with how I'm calling the function? Can anyone point me in the right direction please? I've tried smaller implementations of this script (without making my own functions) and no else/elif statements and it works fine... Sorry for the long post and thanks in advance!
globals()