Created
June 8, 2013 11:08
-
-
Save oogali/5734844 to your computer and use it in GitHub Desktop.
Loopback DNS Server Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import os | |
| import sys | |
| import json | |
| import dns.message | |
| from twisted.internet.protocol import DatagramProtocol | |
| from twisted.internet import reactor | |
| class LoopbackDNS(DatagramProtocol): | |
| def datagramReceived(self, data, (host, port)): | |
| msg = dns.message.from_wire(data) | |
| #print msg.to_text() | |
| query = msg.question[0] | |
| print query | |
| response = dns.message.make_response(msg) | |
| response.set_rcode(dns.rcode.NOERROR) | |
| rrset = dns.rrset.from_text(query.name, 60, dns.rdataclass.IN, dns.rdatatype.A, '127.0.0.1') | |
| response.answer.append(rrset) | |
| self.transport.write(response.to_wire(), (host, port)) | |
| reactor.listenUDP(53, LoopbackDNS()) | |
| reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you give some details to every line and describe what each function do
or please send me a manual of this dns because I really need it thanks.