Microsoft Word - USP 32547 Assignment S2020.docx
1
University of Technology Sydney
Faculty of Engineering and Information Technology
Subject 32547 UNIX Systems Programming, Spring 2020
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 in any way.
Marks
The assignment co
esponds to 30% of the total marks.
Submission
The completed assignment is due by 5:00pm of Friday 23 October 2020.
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 a
anged
in advance with the Subject Coordinator.
2
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
eferencing).
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
equested output.
24-29 The program works co
ectly with any valid file and for all options,
ut 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 e
ors;
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.
3
Title: Processing a hosts file with Python
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.py
2. It should be invoked as:
python hosts.py option hosts_file
The program must check that argument hosts_file exists, is a file and is readable. If not, it
must print an e
or 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 a
itrary name. It must be a file of text with the following format:
a. The file consists of an a
itrary number of lines (including, possibly, zero lines).
. 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:
XXXXXXXXXX).
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:
XXXXXXXXXXlocalhost.localdomain sahara
XXXXXXXXXXfoo.mydomain.edu foo
XXXXXXXXXXwww.opensource.org picco
XXXXXXXXXXbar.mydomain.com bar
XXXXXXXXXXmaster.debian.org master
4
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
ar.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
epresents 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:
XXXXXXXXXXwww.opensource.org picco
XXXXXXXXXXmaster.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:
5
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).
(Note: purely for reference, this option is inspired by a superseded feature of IP addresses
known 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_file
Output:
XXXXXXXXXXlocalhost.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:
XXXXXXXXXXmaster.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:
XXXXXXXXXXfoo.mydomain.edu foo
XXXXXXXXXXwww.opensource.org picco
XXXXXXXXXXbar.mydomain.com 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:
6
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 inco
ect syntax:
python hosts.py -Z hosts_file
python hosts.py -a
python hosts.py -c D
Please be reminded that:
This assignment must be your own work and you should not be helped by anyone to prepare
it in any way; your assignment may be tested by anti-plagiarism software that detects
superficial changes such as changing variable names, swapping lines of code and the like.
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.