Home / Expert Answers / Computer Science / question-a-write-a-script-to-help-confirm-that-an-ipv4-address-is-a-private-address-if-the-ip-addre-pa310

(Solved): Question A:Write a script to help confirm that an IPv4 address is a private address. If the IP addre ...



Question A:

Write a script to help confirm that an IPv4 address is a private address. If the IP address is a
private IPv4, the following message is printed to the screen:
i. “’addr’ is a valid class ‘X’ private IPv4 address!” where “addr” is the IPv4 address
entered and ‘X’ is the class of the address and can be A, B, C, D, or E.
Note: An IPv4 address has four parts (octets) separated y a dot (.), like 10.2.3.4. For
simplicity, use the following table to identify the class of an IPv4 address a.b.c.d. According to
the table, 10.2.3.4 is of class A, and 192.168.2.2 is of class C.
Interval of “a” (IP = a.b.c.d) Class
1 <= a <= 127 A
128 <= a <= 191 B
192 <= a <= 223 C
224 <= a <= 239 D
240 <= a <= 254 E
Other Invalid
ii. However, is the input not a valid private IPv4 address, the printed messages will be:
“Sorry, this is not a valid private IP address; Try again or enter -1 to quit.” In this case,

the user is allowed to try again for a total of 3 times; then the program will stop if the
user keeps entering non-private IP addresses.
iii. The script (module) must have one function and the “if “__name__” == “__main__:”
statement. Under the “if “__name__” == “__main__:” statement, the user is asked to input
an IPv4 address. Because of the requirement ii, there should be within a loop.
iv. When called, the function will accept the address as a parameter, verify the validity,
determine the class, and do the printing.
v. You may name the function and the module as you want.
The script must be callable from a Windows Terminal.
Hint: You can use the Python built-in module “ipaddress”. This is an example of how it is used
(do some more research on the ipaddress module):
ipaddress.ip_address('10.1.1.1').is_private will return “True”
Test data:
 10.2.3.4
 192.168.2.2
 241.5.5.5
 256.30.10.20
 172.16.5.220



We have an Answer from Expert

View Expert Answer

Expert Answer





This question requires the creation of a Python script to validate whether an IPv4 address is a priv...
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe