- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
北邮计算机网络课程设计 DNS 服务器
1 环境
操作系统随意,语言 python2.7
2. 文件
Socket.py 说明 完成缓存检测,确定是回应,还是转发,如果是回应,确定是本地回 应还是外部应答转发
import socket
import mydic
import charhandle
import makeframe
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM
port = 53
the_dic = mydic.get_web_ip(
client_request = {}
client_request_index = {}
reverse_map = {}
key_record = 0
client_wait = []
s.bind((,port
time_rest = 0
request_general =
print running
while True:
try:
msg , (client,port = s.recvfrom(1024
except:
print Time out!
continue
request = []
request = list(msg
requre_web = charhandle.get_request(request[12:]
website = .join(requre_web
if(port == 53:
answer = []
answer = list(msg
print Type:Remote Response
print remote answer is:
response_ip = msg[-4]+msg[-3]+msg[-2]+msg[-1]
char_ip = socket.inet_ntoa(response_ip
print website + has the ip : +char_ip
fre = mydic.storeForUpdate(website,char_ip
print with the frequence of + str(fre
###real_request = client_request[request[0]+request[1]]
for each_client in client_wait:
my_key = client_request[request[0]+request[1]+str(each_client] if client_request_index.get(my_key != None :
s.sendto(msg,client_request_index[my_key]
print Response to ip and Client port:
print client_request_index[my_key]
break
else:
print Type: Client Request
print ip and port:
print (client,port
### requre_web = charhandle.get_request(request[12:]
### website = .join(requre_web
print Request website:+website
if(the_dic.get(website != None:
print Found in local cache:
re_ip = the_dic.get(website
print re_ip
fre = mydic.storeForUpdate(website
print re_ip[0]+ with frequence +str(fre
zhen = makeframe.make(re_ip[0],msg
s.sendto(zhen,(client,port
else:
print need to ask remote server
key_record = key_record + 1
request_general = key_record
client_request[request[0]+request[1]+str(client] = request_general
client_request_index[request_general] = (client,port
if client not in client_wait:
client_wait.append(client
# select authority DNS server as you wish
s.sendto(msg,(,53
time_rest = time_
您可能关注的文档
最近下载
- 出租车驾驶员从业资格考试考试练习题及答案.docx VIP
- 小学语文六年级下册说课标说教材.doc VIP
- 风电项目施工工艺及流程介绍.pptx VIP
- 一种基于人工智能的智慧园区能耗智能管理方法及系统.pdf VIP
- ASDA-A2的台达交流伺服驱动器.pdf VIP
- 温州市工业与能源发展集团有限公司考试试卷.pdf
- 数字逻辑与设计——运动码表实验报告.docx VIP
- 2025浙江温州市工业与能源发展集团有限公司春季招聘19人笔试历年参考题库附带答案详解.pdf
- 2023年06月国家国防科技工业局核技术支持中心社会招考聘用笔试历年难、易错考点试题含答案解析.docx
- 人教版七年级上册英语单词表2115.pdf VIP
原创力文档


文档评论(0)