Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Twisted DNS server!
# twistd -y
import socket
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
from twisted.names import dns
from twisted.names import client, server
TO = ''
TTL = 60
class DNSServerFactory(server.DNSServerFactory):
def gotResolverResponse(self, (ans, auth, add), protocol, message, address):
qname = message.queries[0]
if CHANGE in qname:
for answer in ans:
if answer.type != dns.A:
if CHANGE not in
answer.payload.address = socket.inet_aton(TO)
answer.payload.ttl = TTL
args = (self, (ans, auth, add), protocol, message, address)
return server.DNSServerFactory.gotResolverResponse(*args)
verbosity = 0
resolver = client.Resolver(servers=[('', 53)])
factory = DNSServerFactory(clients=[resolver], verbose=verbosity)
protocol = dns.DNSDatagramProtocol(factory)
factory.noisy = protocol.noisy = verbosity
reactor.listenUDP(53, protocol)
reactor.listenTCP(53, factory)

This comment has been minimized.

Show comment
Hide comment

jack1235675 Aug 3, 2017

Can you explain this code to me? thank you

Can you explain this code to me? thank you

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