Skip to content

Instantly share code, notes, and snippets.

@oogali
Created June 8, 2013 11:08
Show Gist options
  • Select an option

  • Save oogali/5734844 to your computer and use it in GitHub Desktop.

Select an option

Save oogali/5734844 to your computer and use it in GitHub Desktop.
Loopback DNS Server Test
#!/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()
Copy link

ghost commented Jun 9, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment