3

I'm looking to do something like this in python using dnspython:

 dig @XXX.YYY.ZZZ.AAA -p 99 +short '1.1.1.1.1.1.1.1.1.1.1.e164.arpa' naptr

I thought dns.resolver.query would be the way to go, but it seems to choke on the IP address.

My code:

for rdata in dns.resolver.query('XXX.YYY.ZZZ.AAA', 'NAPTR') :
print rdata.target

Output from running the code:

  Traceback (most recent call last):
  File "...\src\dnslookup.py", line 12, in <module>
    for rdata in dns.resolver.query('XXX.YYY.ZZZ.AAA', 'NAPTR') :
  File "build\bdist.win-amd64\egg\dns\resolver.py", line 920, in query
  File "build\bdist.win-amd64\egg\dns\resolver.py", line 856, in query
dns.resolver.NXDOMAIN
4

1 回答 1

1

正如 OXC 指出的那样,您的代码正在查询 XXX.YYY.ZZZ.AAA 的 NAPTR 记录,这与您的 dig 命令不等效。

这是与您的 dig 命令更匹配的代码:

resolver = dns.resolver.Resolver()
resolver.nameservers = ['XXX.YYY.ZZZ.AAA']
resolver.port = 99

resolver.query('1.1.1.1.1.1.1.1.1.1.1.e164.arpa', 'NAPTR')
# Need to confirm syntax for NAPTR query
于 2013-01-08T04:49:31.640 回答