Created
October 24, 2012 02:11
-
-
Save hagna/3943320 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
from twisted.application import internet, service | |
from twisted.web import proxy, server, vhost | |
from twisted.internet.protocol import Factory, Protocol | |
from twisted.internet import reactor | |
from twisted.names import dns | |
from twisted.names import client | |
from twisted.names.server import DNSServerFactory | |
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 | |
import socket, sys | |
vhostName = 'timeandtemp.com' | |
reverseProxy = proxy.ReverseProxyResource('floating-wave-8120.herokuapp.com', 80 , '') | |
root = vhost.NameVirtualHost() | |
root.addHost(vhostName, reverseProxy) | |
class FakeResolver(client.Resolver): | |
def _lookup(self, name, cls, qtype, timeout): | |
""" | |
The getHostByNameTest does a different type of query that requir es 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='10.0.0.1', ttl=60)) | |
results = [rr] | |
authority = [] | |
addtional = [] | |
return defer.succeed((results, authority, addtional)) | |
verbosity = 0 | |
site = server.Site(reverseProxy) | |
application = service.Application('bulletinboard') | |
sc = service.IServiceCollection(application) | |
i = internet.TCPServer(8080, site) | |
i.setServiceParent(sc) | |
resolver = FakeResolver(servers=[('4.2.2.2', 53)]) | |
factory = DNSServerFactory(clients=[resolver], verbose=verbosity) | |
protocol = dns.DNSDatagramProtocol(factory) | |
factory.noisy = protocol.noisy = verbosity | |
i = internet.TCPServer(5353, factory) | |
i.setServiceParent(sc) | |
i = internet.UDPServer(5353, protocol) | |
i.setServiceParent(sc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment