Created
August 8, 2017 18:55
-
-
Save jeffgreenca/e1694f1f461a8f3b53dc2ba2ae019371 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
# Split Brain DNS Stupidly Simple | |
# Edit the script and run it, point your DNS client to 127.0.0.1 or whatever | |
from twisted.internet import reactor, defer | |
from twisted.names import client, dns, error, server | |
class DynamicResolver(object): | |
#List of custom domain names and their associated DNS server | |
_custom = [ ('yourdomain.local', '1.2.3.4'), | |
('anotherdomain.com', '192.168.1.1'), | |
('sub.domain.yours', '10.0.0.1') | |
] | |
def query(self, query, timeout=None): | |
for o in self._custom: | |
if o[0] in query.name.name: | |
print "Using custom DNS for", query.name.name | |
customClient = client.Resolver(servers=[ ( o[1], 53 ) ]) | |
return customClient.query(query) | |
return defer.fail(error.DomainError()) | |
def main(): | |
#Fallback DNS server is 8.8.8.8 | |
factory = server.DNSServerFactory( | |
clients=[DynamicResolver(), client.Resolver(servers=[ ("8.8.8.8",53) ])] | |
) | |
protocol = dns.DNSDatagramProtocol(controller=factory) | |
reactor.listenUDP(53, protocol) | |
reactor.listenTCP(53, factory) | |
reactor.run() | |
if __name__ == '__main__': | |
raise SystemExit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment