Write a python script called hoster-toaster.py that is used to update a machine's local hostname resolution file. The details of how it works are below:It requires one argument on the command...

Creating a short Python script


Write a python script called hoster-toaster.py that is used to update a machine's local hostname resolution file. The details of how it works are below: It requires one argument on the command line: the absolute path to a file it will read data from. It will use the information in that file to alter the machine's /etc/hosts file. If it is run with no other options, it will overwrite the contents of /etc/hosts using the new data in the file provided as the argument. If the script is run with the option -a it will update the data currently in /etc/hosts with the information in the provided file. If an ip address in the provided file is not already in /etc/hosts, the entry (and its corresponding hostnames) will be added to /etc/hosts. If an ip address in the provided file is already in /etc/hosts, the entry already in /etc/hosts will be replaced entirely. If it is run with the option -q it will add the data from the provided file to whatever is currently in /etc/hosts. Note: This option can not be used in the same run of the command as -a If an ip address in the provided file is not already in /etc/hosts, the entry (and its corresponding hostnames) will be added to /etc/hosts. If an ip address in the provided file is already in /etc/hosts, the hostnames listed for it in the provided file will be added to the ones already in /etc/hosts. Note that regardless of the options used, the ipv4 and ipv6 localhost addresses /etc/hosts must not be altered. Note that if any issues are encountered while accessing either of /etc/hosts or the file provided by the user, your script must handle them gracefully. Giving an error message and exiting is permissable, crashing is not. Note that you must make use of python's file editing capabilities. Simply re-directing output from a command into the file will not be accepted. The format for the provided file will always be: One address entry per line. Each line will consist of a valid ipv4 address, a :, and a comma-separated list of hostnames that correspond to that address. You may assume that the ipv4 addresses in the file are valid.
Dec 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here