Subject 32547 UNIX Systems Programming, Autumn 2023
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Subject 32547 UNIX Systems Programming, Autumn 2023
Assignment
Description
This assignment is an individual programming assignment using Python. It addresses objectives 2 and 3 as listed in the Subject Outline document.
No limits apply to the number of lines of code of the program.
Assignments are to be completed individually (this might be checked with the use of anti- plagiarism tools such as Turnitin). You should not receive help in the preparation of this assignment, nor ask anyone else to prepare it on your behalf, nor utilise generative AI tools such as GitHub Copilot or similar in any way.
Marks
The assignment corresponds to 30% of the total marks.
Submission
The completed assignment is due by 5:00pm of Friday 19 May 2023.
PLEASE PAY ATTENTION TO THE FOLLOWING SUBMISSION INSTRUCTIONS:
1. Your Python program has to be submitted on Canvas, following the “Assignments” menu and then the “Assignment” link by the due date. You can prepare your Python program anywhere you like, but probably the easiest option is to develop it in a workspace that you can create in Ed STEM.
2. Please submit only your Python program, and nothing else (no data files).
3. Late submissions will be deducted one mark per day late; more than seven days late, the assignment will receive zero. Special considerations for a late submission must be arranged in advance with the Subject Coordinator.
Academic Standards
The assignments in this Subject should be your own original work. Any code taken from a textbook, journal, the Internet or any other source should be acknowledged. For referencing, please use the standard referencing conventions (http://www.lib.uts.edu.au/help/referencing).
Marking Scheme
Mark Range |
|
30 |
All requirements of the assignment are met. The submitted program can be executed by the lecturer “as is” and produces the requested output. |
24-29 |
The program works correctly with any valid file and for all options, but its execution experiences some minor problems. |
18-23 |
The program does not work as expected with one of the options. |
0-17 |
This range goes from no submission at all (0 marks) to a submission which does not meet major requirements of the assignment. Examples: • the program does not work as expected with two or more options; • the program generates unhandled errors; • the program does not solve the assignment problem. |
The assignments will be marked within two weeks from the submission deadline or as soon as possible.
Important notes:
• Submission of this assignment is not compulsory to pass the subject; do not feel that you have to submit it “at all costs” and perhaps be tempted to seek unauthorised assistance.
• There are no minimum requirements on the marks on this assignment to pass the subject.
• This assignment must be your own work and you should not be helped to prepare it in any
way; your assignment may be tested with anti-plagiarism software that detects superficial
changes such as changing variable names, swapping lines of code and the like.
• The subject coordinator may ask you to describe your assignment in a “viva voce” in Zoom to
finalise your mark.
• Understanding the assignment specifications is part of the assignment itself and no further instructions will be provided; on the other hand, whatever is not constrained you can implement
it according to your own best judgment.
Title: Processing a hosts file with Python
In this assignment, you will write a Python program which reads 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.py
2. It should be invoked as:
python hosts.py option hosts_file
In the command line above, option means one of the options described below, and
hosts_file means the name of the chosen argument file. They are not literal strings. The 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 dot- decimal 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 192.168.1.10 209.237.226.90
localhost.localdomain foo.mydomain.edu www.opensource.org
sahara
foo
picco
192.168.1.13 146.82.138.7
bar.mydomain.com
master.debian.org
bar
master
4. 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:
<first hostname>
<second hostname>
…
<last hostname>
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 hosts
5. 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
146.82.138.7 master.debian.org
picco
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 domain
6. 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).
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_file
Output:
127.0.0.1 localhost.localdomain sahara
In 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_file
Output:
146.82.138.7 master.debian.org master
In 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. This is an example with file hosts_file given above:
Command line:
python hosts.py -c C hosts_file
Output:
192.168.1.10
209.237.226.90
192.168.1.13
foo.mydomain.edu
www.opensource.org
bar.mydomain.com
foo
picco
bar
In the case in which no line of file hosts_file matches the class argument (including the case where the file is empty), your program must print:
No hosts in the given class
7. Your program can be invoked with option: -v. In this case, it must only print your name, surname, student ID and date of completion of your assignment, in a format of your choice. Please note that argument hosts_file is still required.
8. No options can be used simultaneously. This means that your program can only be invoked with one of the options at a time.
9. If your program is invoked with any other syntax than those specified above, it must print a message of your choice to the standard output and exit.
Examples of incorrect syntax:
python hosts.py -Z hosts_file
python hosts.py -a
python hosts.py -c D
2023-05-19