Created
October 23, 2012 22:08
-
-
Save hagna/3941965 to your computer and use it in GitHub Desktop.
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
import socket, sys | |
from twisted.internet.protocol import Factory, Protocol | |
from twisted.internet import reactor | |
from twisted.names import dns | |
from twisted.names import client, server | |
from twisted.python import log | |
from twisted.internet import defer | |
from twisted.names.common import ResolverBase | |
CHANGE = 'example.com' | |
TO = '127.0.0.1' | |
TTL = 60 | |
class FakeResolver(client.Resolver): | |
def _lookup(self, name, cls, qtype, timeout): | |
""" | |
The getHostByNameTest does a different type of query that requires it | |
return an A record from an ALL_RECORDS lookup, so we accomodate that | |
here. | |
""" | |
rr = dns.RRHeader(name=name, type=dns.A, cls=cls, ttl=60, | |
payload=dns.Record_A(address='127.0.0.1', ttl=60)) | |
results = [rr] | |
authority = [] | |
addtional = [] | |
return defer.succeed((results, authority, addtional)) | |
verbosity = 0 | |
resolver = FakeResolver(servers=[('4.2.2.2', 53)]) | |
factory = server.DNSServerFactory(clients=[resolver], verbose=verbosity) | |
protocol = dns.DNSDatagramProtocol(factory) | |
factory.noisy = protocol.noisy = verbosity | |
log.startLogging(sys.stdout) | |
reactor.listenUDP(53, protocol) | |
reactor.listenTCP(53, factory) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment