Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@guerrerocarlos
Last active February 27, 2018 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save guerrerocarlos/8463334 to your computer and use it in GitHub Desktop.
Save guerrerocarlos/8463334 to your computer and use it in GitHub Desktop.
Local DNS Mirror Server with custom UDP port connection to master ProxyDNS server. This script should help users who's ISP do not allow them to use of external DNS services. By running this script in a local computer, and defining that computer's IP to the rest of the devices, all devices will be able to use ProxyDNS.
from twisted.names import dns, server, client, cache
from twisted.application import service, internet
from twisted.internet import defer
from twisted.python import log
import socket
PROXYDNS_MASTER = '50.116.28.138'
PROXYDNS_PORT = 5353
def show_instructions():
hostname = socket.gethostname()
IP = socket.gethostbyname(hostname)
print """
***********************************************************************
Welcome to ProxyDNS Local Server
Beta Version (0.1)
This program creates a local mirror of the main ProxyDNS
servers for you to use in your local network (and avoid ISP
DNS spoofing and DNS blocking).
IMPORTANT: YOU MUST ALLOW ANY WINDOWS FIREWALL WARNING FOR IT TO WORK
Instead of using normal ProxyDNS Servers,
(74.207.242.213 and 50.116.28.138) you must now configure
the IP of this computer in all the devices you want to use
ProxyDNS with, including this one.
The IP of this computer, and the one you must use now as your
DNS server is:
""" + IP + """
*** IMPORTANT: YOU MUST LEAVE THIS BLACK WINDOW OPEN ***
In order to serve as the DNS server of the rest of your devices.
If you close it, the local DNS server will also stop.
To close it: Ctrl+C
"""
class LocalResolverBackend(client.Resolver):
def __init__(self, servers=None):
client.Resolver.__init__(self, servers=servers)
self.ttl = 5
@defer.inlineCallbacks
def _get_ip_addr(self, hostname, timeout):
i = yield self._lookup(hostname, dns.IN, dns.A, timeout)
defer.returnValue(i)
def lookupAddress(self, name, timeout = None):
return self._get_ip_addr(name, timeout)
if __name__ == '__main__':
from twisted.internet import reactor
show_instructions()
localBackend = LocalResolverBackend(servers=[(PROXYDNS_MASTER, PROXYDNS_PORT)])
application = service.Application("ProxyDNS")
srv_collection = service.IServiceCollection(application)
dnsFactory = server.DNSServerFactory(caches=[cache.CacheResolver()], clients=[localBackend])
reactor.listenTCP(53, dnsFactory)
reactor.listenUDP(53, dns.DNSDatagramProtocol(dnsFactory))
reactor.run()
else:
localBackend = LocalResolverBackend(servers=[(PROXYDNS_MASTER, PROXYDNS_PORT)])
application = service.Application("ProxyDNS")
show_instructions()
srv_collection = service.IServiceCollection(application)
dnsFactory = server.DNSServerFactory(caches=[cache.CacheResolver()], clients=[localBackend])
internet.TCPServer(53, dnsFactory).setServiceParent(srv_collection)
internet.UDPServer(53, dns.DNSDatagramProtocol(dnsFactory)).setServiceParent(srv_collection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment