I’m fiddling around a bit with Python. I’m planning to write a little script that pings a host or hosts and logs it to a file. Should be pretty basic but it’s good practice for me to take user input, read from a file, write to a file and so on. I wanted to support having arguments in the script to do things like a continuous ping or ping with x number of packets and then stop. To help the user pick the arguments I planned to do a little help text that printed out the arguments. Something like:
# Import sys import sys # Function for printing help text def help_text(): print "Daniel's awesome ping script." print "\n" print "-c The number of packets that should be sent(integer)" print "-t Timeout in seconds to wait for ICMP Echo Reply" print "-i Run continuous ping" # Check if user has input any options otherwise print help text if len(sys.argv) < 2: help_text()
The problem with doing this manually is that you have to parse the arguments and build the logic yourself. For example the script should not allow someone to input both -c and -i since those arguments should be mutually Continue reading