北邮计算机网络课程设计DNS服务器(共10页).doc
《北邮计算机网络课程设计DNS服务器(共10页).doc》由会员分享,可在线阅读,更多相关《北邮计算机网络课程设计DNS服务器(共10页).doc(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上北邮计算机网络课程设计 DNS 服务器1 环境操作系统随意,语言 python2.72. 文件Socket.py 说明 完成缓存检测,确定是回应,还是转发,如果是回应,确定是本地回 应还是外部应答转发import socketimport mydicimport charhandleimport makeframes = socket.socket(socket.AF_INET, socket.SOCK_DGRAMport = 53the_dic = mydic.get_web_ip(client_request = client_request_index = re
2、verse_map = key_record = 0client_wait = s.bind(,porttime_rest = 0request_general = print runningwhile True:try:msg , (client,port = s.recvfrom(1024except:print Time out! continuerequest = request = list(msgrequre_web = charhandle.get_request(request12:website = .join(requre_webif(port = 53:answer =
3、answer = list(msgprint Type:Remote Responseprint remote answer is: response_ip = msg-4+msg-3+msg-2+msg-1char_ip = socket.inet_ntoa(response_ipprint website + has the ip : +char_ipfre = mydic.storeForUpdate(website,char_ip print with the frequence of + str(fre#real_request = client_requestrequest0+re
4、quest1for each_client in client_wait:my_key = client_requestrequest0+request1+str(each_client if client_request_index.get(my_key != None :s.sendto(msg,client_request_indexmy_keyprint Response to ip and Client port:print client_request_indexmy_keybreakelse:print Type: Client Requestprint ip and port:
5、print (client,port# requre_web = charhandle.get_request(request12:# website = .join(requre_webprint Request website:+websiteif(the_dic.get(website != None:print Found in local cache:re_ip = the_dic.get(websiteprint re_ipfre = mydic.storeForUpdate(websiteprint re_ip0+ with frequence +str(frezhen = ma
6、keframe.make(re_ip0,msgs.sendto(zhen,(client,portelse:print need to ask remote serverkey_record = key_record + 1request_general = key_recordclient_requestrequest0+request1+str(client = request_generalclient_request_indexrequest_general = (client,portif client not in client_wait:client_wait.append(cl
7、ient# select authority DNS server as you wishs.sendto(msg,(10.3.9.4,53time_rest = time_rest+1try:if(time_rest = 50:print pay attentionprint #mydic.updateCache(print #the_dic = mydic.get_web_ip(time_rest = 0except:print not valid frequenceprint -s.close(Mydic.py 完成本地查询, LRU 算法维护本地缓存, socket.py 第 97行的
8、 time_request值可以 确定更新缓存的频率,可以直接输出在 dnsrelay.txt 内,但是为了方便观测变化,我输出到 了 dnsrelaycopy.txt 里面,运行一段时间之后,可以去看看学习到的新条目import pickleimport osimport threadingA=d_web_ip = d_ip_web = update_dic = data = open(dnsrelay.txtfor each_line in data:try:(ip,sitecopy = each_line.split( ,1(site,nothing = str(sitecopy.spl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机网络 课程设计 DNS 服务器 10
限制150内