![北郵計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)DNS服務(wù)器_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/0053ba70-0927-42bd-88b1-53f4b396831b/0053ba70-0927-42bd-88b1-53f4b396831b1.gif)
![北郵計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)DNS服務(wù)器_第2頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/0053ba70-0927-42bd-88b1-53f4b396831b/0053ba70-0927-42bd-88b1-53f4b396831b2.gif)
![北郵計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)DNS服務(wù)器_第3頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/0053ba70-0927-42bd-88b1-53f4b396831b/0053ba70-0927-42bd-88b1-53f4b396831b3.gif)
![北郵計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)DNS服務(wù)器_第4頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/0053ba70-0927-42bd-88b1-53f4b396831b/0053ba70-0927-42bd-88b1-53f4b396831b4.gif)
![北郵計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)DNS服務(wù)器_第5頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/0053ba70-0927-42bd-88b1-53f4b396831b/0053ba70-0927-42bd-88b1-53f4b396831b5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、北郵計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì) DNS 服務(wù)器1 環(huán)境操作系統(tǒng)隨意,語(yǔ)言 python2.72. 文件Socket.py 說(shuō)明 完成緩存檢測(cè),確定是回應(yīng),還是轉(zhuǎn)發(fā),如果是回應(yīng),確定是本地回 應(yīng)還是外部應(yīng)答轉(zhuǎn)發(fā)import socketimport mydicimport charhandleimport makeframes = socket.socket(socket.AF_INET, socket.SOCK_DGRAMport = 53the_dic = mydic.get_web_ip(client_request = client_request_index = reverse_map = k
2、ey_record = 0client_wait = s.bind('',porttime_rest = 0request_general = ''print 'running'while True:try:msg , (client,port = s.recvfrom(1024except:print 'Time out! 'continuerequest = request = list(msgrequre_web = charhandle.get_request(request12:website = ''.
3、join(requre_webif(port = 53:answer = answer = list(msgprint "Type:Remote Response"print "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
4、'with the frequence of '+ str(fre#real_request = client_requestrequest0+request1for 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 por
5、t:"print client_request_indexmy_keybreakelse:print "Type: Client Request"print "ip and port:"print (client,port# requre_web = charhandle.get_request(request12:# website = ''.join(requre_webprint "Request website:"+websiteif(the_dic.get(website != None:print
6、 "Found in local cache:"re_ip = the_dic.get(websiteprint re_ipfre = mydic.storeForUpdate(websiteprint re_ip0+' with frequence '+str(frezhen = makeframe.make(re_ip0,msgs.sendto(zhen,(client,portelse:print "need to ask remote server"key_record = key_record + 1request_genera
7、l = key_recordclient_requestrequest0+request1+str(client = request_generalclient_request_indexrequest_general = (client,portif client not in client_wait:client_wait.append(client# select authority DNS server as you wishtime_rest = time_rest+1try:if(time_rest = 50:print 'pay attention'print &
8、#39;#'mydic.updateCache(print '#'the_dic = mydic.get_web_ip(time_rest = 0except:print 'not valid frequence'print '-'s.close(Mydic.py 完成本地查詢, LRU 算法維護(hù)本地緩存, socket.py 第 97行的 time_request值可以 確定更新緩存的頻率,可以直接輸出在 dnsrelay.txt 內(nèi),但是為了方便觀測(cè)變化,我輸出到 了 dnsrelaycopy.txt 里面,運(yùn)行一段時(shí)間之后,可以去看
9、看學(xué)習(xí)到的新條目import pickleimport osimport threadingA=d_web_ip = d_ip_web = update_dic = data = open('dnsrelay.txt'for each_line in data:try:(ip,sitecopy = each_line.split(' ',1(site,nothing = str(sitecopy.split('n',1d_web_ipsite = ip,1d_ip_webip = siteexcept:print 'file error&
10、#39;data.close(try:with open('newdnsrelay.pickle','wb' as newdnsrelay_file:pickle.dump(d_web_ip,newdnsrelay_fileexcept IOError as err:print 'File error:'+str(errexcept pickle.PickleError as perr:print 'Pickling error:'+str(perrdef get_web_ip(:with open('newdnsrela
11、y.pickle','rb' as f:global update_dicupdate_dic = pickle.load(freturn update_dic.copy(return(Nonedef storeForUpdate(web_site, add = None:global update_dicif(update_dic.get(web_site != None:add_frequen = update_dicweb_siteadd_frequen1 = add_frequen1 + 1print web_site+' frequence incra
12、se 1,with ip '+add_frequen0 return add_frequen1else:update_dicweb_site = add,1print 'record for a new site'return 1def updateCache(:global update_dicm = update_dic.copy(t = threading.Thread(target = my_thread,kwargs = m print 'ready to update local cache't.start(t.join(def my_thr
13、ead(*argu,*arg:frequence = remain_dic = for each_key in arg:tmp = argeach_keyif(tmp1 not in frequence:frequence.append(tmp1print 'various frequence:'for each in frequence:print 'have '+ str(eachfor each_key in remain_dic:arg.pop(each_key#enimilate bani = 0while(i < 30:max_frequenc
14、e = max(frequencefor each_key in arg:tmp = argeach_keyif(tmp1 = max_frequence:remain_diceach_key = tmp0i = i + 1if(i = 30:break;frequence.remove(max_frequenceif(not frequence:#no morebreak;updateFile(remain_dicdef updateFile(new_dic:f = open('dnsrelaycopy.txt','w'for each_key in new_
15、dic:word = str(new_diceach_key + ' ' + str(each_key f.write(wordf.write('n' new_diceach_key = new_diceach_key,0 try: with open('newdnsrelay.pickle','wb' as newdnsrelay_file: pickle.dump(new_dic,newdnsrelay_file except IOError as err: print 'File error:'+str(er
16、r except pickle.PickleError as perr: print 'Pickling error:'+str(perr Makefram.py 成幀模塊,形成對(duì)外圍權(quán)威服務(wù)器的詢問(wèn)幀 import socket def make(re_ip,msg: tmp_list = for ch in msg: tmp_list.append(ch tmp_list4:12 = 'x00','x01','x00','x01','x00','x00','x00'
17、;,'x00' tmp_list = tmp_list+'xc0','x0c','x00','x01','x00 ','x01','x00','x00','x02','x58','x00','x04' dive_ip = socket.inet_aton(re_ip ch_ip = for each_ch in dive_ip: ch_ip.append(each_ch tmp_list
18、= tmp_list + ch_ip re_msg = ''.join(tmp_list return re_msg Charhandle.py 提取出報(bào)文中的 url def get_request(your_list: my_list = new_list = my_list.extend(your_list re_list = thelen = ord(my_list0 try: while thelen != 0: new_list = new_list + my_list1:thelen+1 my_list0:thelen+1 = thelen = ord(my_list0 new_list.append('.' except IndexError: print &qu
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度建筑工地施工現(xiàn)場(chǎng)綠化養(yǎng)護(hù)合同標(biāo)準(zhǔn)
- 2025年度工業(yè)地皮買(mǎi)賣(mài)合同風(fēng)險(xiǎn)評(píng)估與控制服務(wù)協(xié)議
- 金華浙江金華市婺城區(qū)三江街道社區(qū)衛(wèi)生服務(wù)中心招聘工作人員筆試歷年參考題庫(kù)附帶答案詳解
- 金華浙江金華義烏市中心醫(yī)院基建總務(wù)科非編人員招聘筆試歷年參考題庫(kù)附帶答案詳解
- 重慶2025年重慶文理學(xué)院招聘39人筆試歷年參考題庫(kù)附帶答案詳解
- 漯河2024年河南共青團(tuán)漯河市委所屬事業(yè)單位引進(jìn)高層次人才筆試歷年參考題庫(kù)附帶答案詳解
- 淄博2024年山東淄博機(jī)電工程學(xué)校招聘教師筆試歷年參考題庫(kù)附帶答案詳解
- 汕尾2025年廣東汕尾陸河縣第一批城鎮(zhèn)公益性崗位招聘筆試歷年參考題庫(kù)附帶答案詳解
- 杭州浙江杭州市上城區(qū)行政審批服務(wù)管理辦公室編外人員招聘筆試歷年參考題庫(kù)附帶答案詳解
- 2025年中國(guó)企業(yè)管理軟件市場(chǎng)調(diào)查研究報(bào)告
- 2024年四川省巴中市級(jí)事業(yè)單位選聘15人歷年高頻難、易錯(cuò)點(diǎn)練習(xí)500題附帶答案詳解
- 演出經(jīng)紀(jì)人培訓(xùn)
- 蓋房四鄰簽字協(xié)議書(shū)范文
- 2024年新人教版七年級(jí)上冊(cè)數(shù)學(xué)教學(xué)課件 第六章 幾何圖形初步 數(shù)學(xué)活動(dòng)
- 《新時(shí)代大學(xué)生勞動(dòng)教育》全套教學(xué)課件
- 2024簡(jiǎn)易租房合同下載打印
- 數(shù)字出版概論 課件 第八章 數(shù)字出版產(chǎn)品開(kāi)發(fā)與分析
- 高職建筑設(shè)計(jì)專業(yè)《建筑構(gòu)造與識(shí)圖》說(shuō)課課件
- 碼頭工程施工組織設(shè)計(jì)
- TBSES 001-2024 建設(shè)項(xiàng)目環(huán)境影響后評(píng)價(jià)技術(shù)指南 污染影響類
- 北師大版數(shù)學(xué)三年級(jí)下冊(cè)《分橘子》說(shuō)課稿及反思(共二篇)
評(píng)論
0/150
提交評(píng)論