mydns - # Assignment 4, CSCI 4211 # Ben Sprague, 3296712 #...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 # Assignment 4, CSCI 4211 # Ben Sprague, 3296712 # DNS Server import os, sys, time, socket, threading, commands, string, re def main(): port = int(sys.argv[1]) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #socket level options sock.bind( ('', port) ) sock.listen(20) s CACHE = open('dnscache.txt', 'w') CACHE.write('\n') CACHE.close() print "Welcome to the DNS Server!" p while 1: try: client, addr = sock.accept() flo = client.makefile('r', 0) hostrequest = flo.readline() fixed = hostrequest.rstrip('\r\n') if (not fixed.find("(") == 0) or (not fixed.find(")")==len(fixed)-1): client.sendall("invalid format") print 'Invalid Format\n' client.close() else: TABLE = open('dnstable.txt','r') data = TABLE.readlines() print 'Checking table' for line in data: fixedhostrequest = hostrequest.rstrip(')') index = 0 while index < len(fixedhostrequest): if line[index] == fixedhostrequest[index]: statement = 'TRUE' index = index + 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

mydns - # Assignment 4, CSCI 4211 # Ben Sprague, 3296712 #...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online