简体   繁体   中英

Reverse DNS lookup using dnspython module

How do I do reverse DNS lookup for a given IP?

nslookup google.com resolves to 172.217.3.46 for me. But when I use dnspython module,

import dns.resolver
import dns.reversename

qname = dns.reversename.from_address('172.217.3.46')
answer = dns.resolver.query(qname, 'PTR')
for rr in answer:
    print(rr)

>> iad23s57-in-f14.1e100.net.
>> iad23s57-in-f46.1e100.net.

I get different DNS name. How do I get google.com in this case?

Your resuts are correct. The reverse IP for the host you are querying does not point to the forward name you started with. There is no guarantee that a reverse PTR exists or that you can round-trip like you expected if one does exist.

One common scenario is HTTP multi-homing. A web server can host multiple domains; large web hosting sites commonly host hundreds of domains on each IP address they own. The reverse DNS for any random web host is statistically likely to be something like webhotel2345.hosting.example.com. rather than the name of any domain hosted there (but sometimes they just set up reverse DNS to the first one they hosted there, or the first client who complained that they want reverse DNS to check out, too).

Some mail servers are set up to reject connections from hosts whose reverse DNS does not round-trip as a (very circumstantial) anti-spam measure, but this has a fairly high rate of false positives, and is considered aggressive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM