summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062
diff options
context:
space:
mode:
Diffstat (limited to 'project2/proj2_s4498062')
-rw-r--r--project2/proj2_s4498062/dns/__init__.py2
-rw-r--r--project2/proj2_s4498062/dns/cache.py2
-rw-r--r--project2/proj2_s4498062/dns/classes.py3
-rw-r--r--project2/proj2_s4498062/dns/domainname.py4
-rw-r--r--project2/proj2_s4498062/dns/message.py16
-rw-r--r--project2/proj2_s4498062/dns/rcodes.py1
-rw-r--r--project2/proj2_s4498062/dns/resolver.py1
-rw-r--r--project2/proj2_s4498062/dns/resource.py3
-rw-r--r--project2/proj2_s4498062/dns/types.py2
-rw-r--r--project2/proj2_s4498062/dns_client.py27
-rw-r--r--project2/proj2_s4498062/dns_server.py22
11 files changed, 50 insertions, 33 deletions
diff --git a/project2/proj2_s4498062/dns/__init__.py b/project2/proj2_s4498062/dns/__init__.py
index 18ff536..992b090 100644
--- a/project2/proj2_s4498062/dns/__init__.py
+++ b/project2/proj2_s4498062/dns/__init__.py
@@ -1 +1 @@
-#!/usr/bin/env python2
+"""DNS tools"""
diff --git a/project2/proj2_s4498062/dns/cache.py b/project2/proj2_s4498062/dns/cache.py
index e148d3a..3ef14b3 100644
--- a/project2/proj2_s4498062/dns/cache.py
+++ b/project2/proj2_s4498062/dns/cache.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python2
-
"""A cache for resource records
This module contains a class which implements a cache for DNS resource records,
diff --git a/project2/proj2_s4498062/dns/classes.py b/project2/proj2_s4498062/dns/classes.py
index 2a6a67d..b6123cd 100644
--- a/project2/proj2_s4498062/dns/classes.py
+++ b/project2/proj2_s4498062/dns/classes.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python2
-
""" DNS CLASS and QCLASS values
This module contains an Enum of CLASS and QCLASS values. The Enum also contains
@@ -18,6 +16,7 @@ class Class(object):
255
"""
+ # pylint: disable=invalid-name
IN = 1
CS = 2
CH = 3
diff --git a/project2/proj2_s4498062/dns/domainname.py b/project2/proj2_s4498062/dns/domainname.py
index 8876b48..81b5f4c 100644
--- a/project2/proj2_s4498062/dns/domainname.py
+++ b/project2/proj2_s4498062/dns/domainname.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python2
-
""" Parsing and composing domain names
This module contains two classes for converting domain names to and from bytes.
@@ -18,7 +16,7 @@ class Composer(object):
self.offsets = dict()
def to_bytes(self, offset, dnames):
- # Convert each domain name in to bytes
+ """Convert each domain name in to bytes"""
result = b""
for dname in dnames:
# Split domain name into labels
diff --git a/project2/proj2_s4498062/dns/message.py b/project2/proj2_s4498062/dns/message.py
index 54933b7..baaba17 100644
--- a/project2/proj2_s4498062/dns/message.py
+++ b/project2/proj2_s4498062/dns/message.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python2
-
""" DNS messages
This module contains classes for DNS messages, their header section and
@@ -15,7 +13,9 @@ from dns.resource import ResourceRecord
class Message(object):
""" DNS message """
- def __init__(self, header, questions=None, answers=None, authorities=None, additionals=None):
+ def __init__(
+ self, header, questions=None, answers=None, authorities=None,
+ additionals=None):
""" Create a new DNS message
Args:
@@ -101,14 +101,14 @@ class Message(object):
# Parse authorities
authorities = []
for _ in range(header.ns_count):
- authority, offset = ResourceRecord.from_bytes(packet, offset, parser)
- authorities.append(authority)
+ auth, offset = ResourceRecord.from_bytes(packet, offset, parser)
+ authorities.append(auth)
# Parse additionals
additionals = []
for _ in range(header.ar_count):
- additional, offset = ResourceRecord.from_bytes(packet, offset, parser)
- additionals.append(additional)
+ addit, offset = ResourceRecord.from_bytes(packet, offset, parser)
+ additionals.append(addit)
return cls(header, questions, answers, authorities, additionals)
@@ -122,6 +122,8 @@ class Header(object):
See section 4.1.1 of RFC 1035 for their meaning.
"""
+ # pylint: disable=missing-docstring, invalid-name
+
def __init__(self, ident, flags, qd_count, an_count, ns_count, ar_count):
""" Create a new Header object
diff --git a/project2/proj2_s4498062/dns/rcodes.py b/project2/proj2_s4498062/dns/rcodes.py
index 4b1d33d..4f40621 100644
--- a/project2/proj2_s4498062/dns/rcodes.py
+++ b/project2/proj2_s4498062/dns/rcodes.py
@@ -6,6 +6,7 @@ This module contains an Enum of RCODE values. See section 4.1.4 of RFC 1035 for
more info.
"""
+
class RCode(object):
""" Enum of RCODE values
diff --git a/project2/proj2_s4498062/dns/resolver.py b/project2/proj2_s4498062/dns/resolver.py
index ba27f74..29451bf 100644
--- a/project2/proj2_s4498062/dns/resolver.py
+++ b/project2/proj2_s4498062/dns/resolver.py
@@ -16,6 +16,7 @@ import dns.cache
import dns.message
import dns.rcodes
+
class Resolver(object):
""" DNS resolver """
diff --git a/project2/proj2_s4498062/dns/resource.py b/project2/proj2_s4498062/dns/resource.py
index fdf51de..19a09bb 100644
--- a/project2/proj2_s4498062/dns/resource.py
+++ b/project2/proj2_s4498062/dns/resource.py
@@ -44,7 +44,8 @@ class ResourceRecord(object):
""" Convert ResourceRecord from bytes """
names, offset = parser.from_bytes(packet, offset, 1)
name = names[0]
- type_, class_, ttl, rdlength = struct.unpack_from("!HHIH", packet, offset)
+ type_, class_, ttl, rdlength = struct.unpack_from(
+ "!HHIH", packet, offset)
offset += 10
rdata = RecordData.from_bytes(type_, packet, offset, rdlength, parser)
offset += rdlength
diff --git a/project2/proj2_s4498062/dns/types.py b/project2/proj2_s4498062/dns/types.py
index f918050..494232c 100644
--- a/project2/proj2_s4498062/dns/types.py
+++ b/project2/proj2_s4498062/dns/types.py
@@ -7,6 +7,7 @@ a method for converting Enum values to strings. See sections 3.2.2 and 3.2.3 of
RFC 1035 for more information.
"""
+
class Type(object):
""" DNS TYPE and QTYPE
@@ -16,6 +17,7 @@ class Type(object):
>>> Type.CNAME
5
"""
+ # pylint: disable=invalid-name
A = 1
NS = 2
CNAME = 5
diff --git a/project2/proj2_s4498062/dns_client.py b/project2/proj2_s4498062/dns_client.py
index b15d566..0f5e50f 100644
--- a/project2/proj2_s4498062/dns_client.py
+++ b/project2/proj2_s4498062/dns_client.py
@@ -7,22 +7,29 @@ A simple example of a client using the DNS resolver.
import dns.resolver
-if __name__ == "__main__":
+
+def main():
+ """DNS client"""
# Parse arguments
import argparse
parser = argparse.ArgumentParser(description="DNS Client")
parser.add_argument("hostname", help="hostname to resolve")
- parser.add_argument("-c", "--caching", action="store_true",
- help="Enable caching")
- parser.add_argument("-t", "--ttl", metavar="time", type=int, default=0,
- help="TTL value of cached entries")
+ parser.add_argument(
+ "-c", "--caching", action="store_true",
+ help="Enable caching")
+ parser.add_argument(
+ "-t", "--ttl", metavar="time", type=int, default=0,
+ help="TTL value of cached entries")
args = parser.parse_args()
-
+
# Resolve hostname
resolver = dns.resolver.Resolver(args.caching, args.ttl)
hostname, aliases, addresses = resolver.gethostbyname(args.hostname)
-
+
# Print output
- print(hostname)
- print(aliases)
- print(addresses)
+ print hostname
+ print aliases
+ print addresses
+
+if __name__ == "__main__":
+ main()
diff --git a/project2/proj2_s4498062/dns_server.py b/project2/proj2_s4498062/dns_server.py
index 07e0d9a..4ac2ec4 100644
--- a/project2/proj2_s4498062/dns_server.py
+++ b/project2/proj2_s4498062/dns_server.py
@@ -7,16 +7,21 @@ This script contains the code for starting a DNS server.
import dns.server
-if __name__ == "__main__":
+
+def main():
+ """DNS server"""
# Parse arguments
import argparse
parser = argparse.ArgumentParser(description="DNS Server")
- parser.add_argument("-c", "--caching", action="store_true",
- help="Enable caching")
- parser.add_argument("-t", "--ttl", metavar="time", type=int, default=0,
- help="TTL value of cached entries (if > 0)")
- parser.add_argument("-p", "--port", type=int, default=5353,
- help="Port which server listens on")
+ parser.add_argument(
+ "-c", "--caching", action="store_true",
+ help="Enable caching")
+ parser.add_argument(
+ "-t", "--ttl", metavar="time", type=int, default=0,
+ help="TTL value of cached entries (if > 0)")
+ parser.add_argument(
+ "-p", "--port", type=int, default=5353,
+ help="Port which server listens on")
args = parser.parse_args()
# Start server
@@ -26,3 +31,6 @@ if __name__ == "__main__":
except KeyboardInterrupt:
server.shutdown()
print()
+
+if __name__ == "__main__":
+ main()