Get source code from : http://libraay.com/downloads/python-s...
In this assignment, you will write a Python program which parses a text file that associates IPv4 addresses and hostnames, and outputs the requested information. Purely for reference, the file is similar in format to the actual Unix file /etc/hosts.These are the specifications for your Python program:1. It must be named hosts.py2. It should be invoked as:python hosts.py option hosts_fileThe program must check that argument hosts_file exists, is a file and is readable. If not, it must print an error message to the standard output and exit. The specifications for the hosts_file and option arguments are given below.3. File hosts_file can have any arbitrary name. It must be a file of text with the following format:a. The file consists of an arbitrary number of lines (including, possibly, zero lines).b. Each line must contain three fields separated by one or more space characters.c. The three fields are: IPv4 address, hostname, alias.d. The IPv4 address field is a string of characters in the well-known IPv4 address dotdecimal format (four integers, each between 0 and 255, separated by dots; example:103.246.98.253).e. The hostname field is a string of characters that can include letters, digits, hyphens (also known as minus signs) and dots. Its length can vary from a minimum of 4 to a maximum of 253 characters.f. The alias field is a string of the same type of characters, varying in length from a minimum of 1 character to an unlimited (yet sensible) number.Fundamental note: your program is not expected to verify that file hosts_file complies with the above specifications. It will only be tested with compliant files.The following example should be regarded as the reference specification for the format of file hosts_file:127.0.0.1 localhost.localdomain sahara192.168.1.10 foo.mydomain.edu foo209.237.226.90 www.opensource.org picco192.168.1.13 bar.mydomain.com bar146.82.138.7 master.debian.org master4. Your program can be invoked with option: -a. In this case, it must print all the hostnames in the order in which they appear in file hosts_file, in this format: Hostnames: … Example with file hosts_file given above: Command line: python hosts.py -a hosts_file Output: Hostnames: localhost.localdomain foo.mydomain.edu www.opensource.org bar.mydomain.com master.debian.org In the case in which file hosts_file is empty, your program must instead only print: No hosts5. Your program can be invoked with option: -d domain. The domain argument is a string that represents the top-level domain of a hostname (the string after the right-most dot in the hostname). For instance, in the file hosts_file given above, strings localdomain, edu, org and com are all top-level domains. Note that there is no dot in the top-level domain. In this case, your program must print all the lines of file hosts_file where the top-level domain of the hostname matches the given domain argument, in the order in which they appear in the file. This is an example with file hosts_file given above: Command line: python hosts.py -d org hosts_file Output: 209.237.226.90 www.opensource.org picco 146.82.138.7 master.debian.org master In the case in which no line of file hosts_file matches the domain argument (including the case where the file is empty), your program must print: No hosts in the given domain6. Your program can be invoked with option: -c class. The class argument is a string of one character that can only take values A, B or C (please note: only uppercase). (Note: purely for reference, this option is inspired by a superseded feature of IP addressesknown as classful network design.)In the case in which the value is A, your program must print all the lines of file hosts_file where the number before the first dot in the IPv4 address field is between 0 and 127, included, in the order in which they appear in the file. This is an example with file hosts_file given above:Command line:python hosts.py -c A hosts_fileOutput:127.0.0.1 localhost.localdomain saharaIn the case in which the value is B, your program must print all the lines of file hosts_file where the number before the first dot in the IPv4 address field is between 128 and 191, included, in the order in which they appear in the file. This is an example with file hosts_file given above:Command line:python hosts.py -c B hosts_fileOutput:146.82.138.7 master.debian.org masterIn the case in which the value is C, your program must print all the lines of file hosts_file where the number before the first dot in the IPv4 address field is between 192 and 255, included, in the order in which they appear in the file.
On this page of the site you can watch the video online Python script for hosts file processing: 32547 UNIX Systems Programming, Spring 2020 with a duration of hours minute second in good quality, which was uploaded by the user Libraay: Your AI Transition Specialist 23 October 2020, share the link with friends and acquaintances, this video has already been watched 73 times on youtube and it was liked by 1 viewers. Enjoy your viewing!