Python – Kirk Byers Course Week 3 Part 3
This post will describe the exercises and solutions for week three of Kirk Byers Python for Network Engineers.
The last exercise of the week is to create an IP address checker that checks the validity of an IP address. Here are the instructions:
IV. Create a script that checks the validity of an IP address. The IP address should be supplied on the command line. A. Check that the IP address contains 4 octets. B. The first octet must be between 1 - 223. C. The first octet cannot be 127. D. The IP address cannot be in the 169.254.X.X address space. E. The last three octets must range between 0 - 255. For output, print the IP and whether it is valid or not.
The IP address will be supplied through the command line. Like we’ve done before we are going to check the number of arguments supplied and exit the script if the number of arguments is not two. We need to import sys so that we can use sys.argv.
import sys if len(sys.argv) != 2: sys.exit("Usage: ./ip_checker.py <IP-ADDRESS>")
We’ll store the IP address as input as dotted decimal into the Continue reading