Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twisted dns doesn't work

Tags:

python

twisted

I'd like to know why the following doesn't work.

from twisted internet import defer, reactor
from twisted.python.failure import Failure
import twisted.names.client

def do_lookup(do_lookup):
    d = twisted.names.client.getHostByName(domain)
    d.addBoth(lookup_done)

def lookup_done(result):
    print 'result:', result
    reactor.stop()

domain = 'twistedmatrix.com'    
reactor.callLater(0, do_lookup, domain) 
reactor.run()

Results in:

result: [Failure instance: Traceback
(failure with no frames): <class
'twisted.names.error.ResolverError'>:
Stuck at response without answers or
delegation ]
like image 831
jack Avatar asked Oct 31 '10 22:10

jack


1 Answers

As of this writing, this fails on Windows, since it uses an invalid path for the windows host file (in twisted.names.client.createResolver. It uses 'c:\windows\hosts'. This was fine for windows versions 98 and Me (reference here), but would fail with a version as "modern" as XP.

Today, it should probably use something like:

hosts = os.path.join(
                     os.environ.get('systemroot','C:\\Windows'),
                     r'system32\drivers\etc\hosts'
                    )

I think this only partly resolves the issue though (or maybe this is a red herring).

This will only work now for names actually specified in this hosts file. What it likely needs to do is some sort of registry query for the DNS server, then query that for the actual DNS name lookup.

This recipe looks promising for getting the actual DNS server.

like image 199
Gerrat Avatar answered Sep 28 '22 08:09

Gerrat