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:
For every task below:
- write your code which performs the task and run it. Display the code and the result on your screen;
- use a snipping (Windows snipping tool) or "print screen" tool to take one or two screenshots that contain the code and the result, and paste the illustration or picture into the document you created in 1. Your goal is to allow me to assess your code and its result.
- Add a comment for every line of code.
Objectives:
- Review if condition and loops
- Create a project
- Create custom modules and import them into a project
- Create a virtual environment and import external packages
Task 1:
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:
- "addr is a private IPv4 address!" where "addr" is the IPv4 address entered.
However, is the input not a private IPv4 address, the printed messages will be:
- "Sorry, this is not a 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.
The script (module) must have two functions and the "if "__name__ == "__main__:" statement.
One function will accept the address and verify the validity, and the other will do the printing; name the functions and the module as you want.
The script can be called 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"
Task 2:
In this task, you will build a project, install packages, and use them in the project.
- Create a main2.py file in the folder
- Create and activate a virtual environment called "venv" in the folder
- In the "venv" virtual environment, install the "netmiko" and "requests" packages
- In the "main2.py" file, write a short function that will verify whether an equipment brand is supported by Netmiko. (hint: "dir(netmiko)" will return a list that contain all supported equipment types.
- One should be able to call the function from the command line terminal. The program will ask for an equipment brand name. When a name is entered, either "... is Supported" or "... is Not Supported" is received as a response.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images