Question
Write a program that reads four integer values corresponding to an IP address a1.a2.a3.a4 (IPv4), and determines whether the values form a valid IP address,
Write a program that reads four integer values corresponding to an IP address "a1.a2.a3.a4" (IPv4), and determines whether the values form a valid IP address, the class of this IP address, and whether or not the values correspond to a reserved IP address space. Your program shall define and use the following functions: is_valid_ip(a1, a2, a3, a4): This function returns True if the address a1.a2.a3.a4 is valid; otherwise, the function returns False. The parameters a1, a2, a3 and a4 form a valid IP address if a1 is between 1 and 255, and the rest of the values are between 0 and 255, both included. determine_ip_class(a1): By providing the a1 component of an IP address, this function return one of the classes below depending on the range a1 falls in: Class Range ----------------- "A" 1 - 127 "B" 128 - 191 "C" 192 - 223 "D" 224 - 239 "E" 240 - 255 is_private_ip(a1, a2, a3, a4): This function returns True if the address a1.a2.a3.a4 falls in one of the address ranges below, considered Private IP Addresses; otherwise the function returns False. Private IP Address ------------------------------- 10.0.0.0 - 10.255.255.255 127.0.0.0 - 127.255.255.255 172.16.0.0 - 172.31.255.255 192.88.99.0 - 192.88.99.255 192.168.0.0 - 192.168.255.255 ------------------------------- main(): This function coordinates all the actions in the program: it asks the user for the components of an IP address, and determines whether it is valid or not. If it is valid, the program also shows the class of the IP address, and whether or not it is considered a private address.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started