A typical exercise for a system involves editting and maintaining DNS zone files. In this lab you will write scripts to read in zone files, check them for validity (that is, check the format of the resource record lines) and then rewrite the files in a formatted manner.
DNS File Reading
The first task is to read in a DNS zone file. A couple of example files are provided with the lab on myCourses. Please use these as test cases, but do NOT assume they cover all tests. Read in the resource records in each file, convert them to Net::DNS::RR objects, and then print them out with the ->print methods, just to check they were all read correctly.
DNS Record Checking
As you read in your records, you should check for a number of issues that arise in these files.
Generally, a missing field in a DNS zone file is treated as a DITTO for the same field in the
previous resource record. So, if you have multiple NS records for a domain, and one folows
the other directly in the zone file, you only need provide the name in the first NS record.
Omitting the name in the second NS record means to reuse the name from the previous record.
myco.com. 1200 IN NS ns1.myco.com.
1200 IN NS ns2.myco.com.
Partially qualified domain names -
If a name appears WITHOUT the trailing dot, it is presumed that you should append the domain name (as
specified on the SOA record) to it. You NEED NOT check for this and I will not test this case.
Missing class -
The class will always be IN for us. However, the IN might be missing on the RR lines of the zone file.
It turns out that Net::DNS::RR assumes IN if the class is missing, so this is OK.
Missing TTL -
The TTL is often (nearly always) missing from a DNS file. This is the same as a TTL of 0 (Net::DNS::RR
uses 0 if the TTL is omitted) and results in the Minimum field of the SOA being sent in response to any
query. Thus, a missing TTL field is OK for us.
DNS File Rewriting
Once you have read in and checked all DNS records, rewrite the file. If the filename was [url removed, login to view], then you should create a file called [url removed, login to view] with your version of the RRs in it. You will have noted that the ->print method of each Net::DNS::RR object comes close to printing out what you need. However, the fields will not line up properly. Thus, you should write your own print sub that will print out any Net::DNS::RR object using the following format:
Name--------------------- TTL------- IN TYPE- RDATA
where the Name is 25 characters long (left justified in the field), the TTL is 10 characters long, right justified in the field, the IN is fixed length (2 characters), the TYPE is 5 characters long, left justified in the field, and RDATA is as long as it needs to be (left justified in the field).
NOTE: There is 1 space between each field.
If ANY field is longer than specified, print it all out, allowing it to overflow into the next field to the right, and shifting the rest of the line right as well. Better to sacrifice our formatting rather than lose critical information.
Use sprintf or any other approach you know to format these lines.
Print the SOA record first (there should only be 1).
Print NS records next.
Print A records next.
Print CNAME records next.
Finally, print MX records.
6 freelance ont fait une offre moyenne de 180 $ pour ce travail
I've been programming in Perl professionally since 2005; I am also a Windows/Linux admin in charge of DNS servers. I can deliver this script for you within 5 days of being chosen.