INFO – 1249 – Programming Fundamentals – Project #1 – IPv4 Break Down
Project #1 – IPv4 Break Down
Code a script / program that produces the required output.
You goal is to create a Python script (Program) that will ask the user for an IPv4 address with the /prefix mask.
(i.e. 192.168.2.155/25 ) From this information, you can determine the following and output this to the user.
The IP Address (The user entered)
The Subnet Mask (Converted from /prefix to dotted decimal format – i.e. /25 255.255.255.128)
The Wildcard Mask (The Inverse of the Subnet Mask – i.e. /25 0.0.0.127)
The Network Address that the host belongs too. (Bitwise AND the IP Address and Subnet Mask)
The Minimum Host IP Address for this network. (Network Address + 1)
The Maximum Host IP Address for this network. (Broadcast Address – 1)
The Broadcast Address for this network. (Bitwise OR the IP Address and Wildcard Mask)
The Number of Hosts per Network allowed on this network.
Create a source code / script file named Your_Initials_IPv4BreakDown.py.
For example, if your name is Harley Quinn, you would name the script HQ_ IPv4BreakDown.py.
A documentation header and Comments are required though out your code.)
Write a short program that does all of the following:
1. Asks the user for an IP Address with the subnet prefix. (i.e. 192.168.2.155/25 )
2. Validate and convert the user input string.
Check for that there are no spaces ” ” in the input string.
Break the input string into IP and Prefix (using “/” to split)
Break the IP (from above) into a list (using “.” to split)
Validate that the prefix must be between (8-31) and each Octet (element in the IP list) must be between (0-255)
If any of the information is incorrect loop back and ask for the input again. (Provide output of the correct format)
3. You must use Separate Lists to store all the Addresses. (~7 List Variables for IP Address, Network Address,
Subnet Mask, Wildcard Mask, Network Broadcast Address, Minimum Host IP, and Maximum Host IP)
i.e. The IP Address should be stored in a 4 element list [ 205, 210, 49, 10 ] The Subnet Mask should be stored in another 4 element list [ 255, 255, 255, 0 ] etc…
4. Using the IP List and Prefix variable to calculate the required answers (to populate the other lists variables).
To calculate the subnet mask convert the /prefix to a string with so many 1s and the rest 0s.
Then break this down into groups of 8 bits for each octet.
(i.e. /25 11111111111111111111111110000000 = 25 x 1s + (32-25) 7 x 0s.
5. Output should provide all answers in dotted decimal and binary. (Must match the provide output sample)