[Twisted-Python] twisted.names.client.getHostByName Error when DNS Server return Auth NS Server

wangmm kernellearn at gmail.com
Mon Oct 15 02:09:08 EDT 2007


 There is a bug in the extractRecord function of common.py. And I open a
ticket in http://twistedmatrix.com/trac/ticket/2850
----------------------------------------------------------------------------------------------------

Python Version:2.5
Twisted Version:2.5
Names Version:0.4


 When we got a resolver and call getHostByname, perhaps DNS server can
return CNAME, Auth NS Server Name and Auth NS Server IP Address. So
extractRecord function will extract the Auth NS Server and send the DNS
request to the Auth NS Server. But there is a bug in the extractRecord
function.

Code:

 # No answers, but maybe there's a hint at who we should be asking about
this for r in answers:

 if r.type == dns.NS:

 from twisted.names import client r = client.Resolver(servers=[(str(
r.payload.name), dns.PORT)]) return r.lookupAddress(str(name)

 Generally, the Auth NS Server is the Domain name, and it's IP contained in
the addition fields. If we get the NS Server by r.payload.name, we will get
the DNS Server Domain, so the Domain as server will pass to
client.queryUDPas DNS Server Address.
UDP.write will complaint that warnings.warn("Please only pass IPs to
write(), not hostnames "+addr[0] <http://twistedmatrix.com/trac/changeset/0>,
DeprecationWarning? <http://twistedmatrix.com/trac/wiki/DeprecationWarning>,
stacklevel=2). In addition, self.socket.sendto(datagram, addr) will call
socket.gethostbyname(addr), but this call is block.

I think we should use the Auth NS Server IP to replace the Domain. The patch
code as fellow:

Any comment is welcome!

 # No answers, but maybe there's a hint at who we should be asking about
this for r in answers:

 if r.type == dns.NS:

 from twisted.names import client

server = str(r.payload.name)

    for s in answers:

 if s.type==dns.A and str(s.name)==server :

 server = socket.inet_ntop(socket.AF_INET, s.payload.address) break

    r = client.Resolver(servers=[(server, dns.PORT)])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20071015/1e9e3ceb/attachment.htm 


More information about the Twisted-Python mailing list