Ad

Gethostbyaddr Gives A Different Host Name

- 1 answer

My gethostbyaddr() is giving a different host name from what I need. The host name that I need does not even show up in the alias list.

So, I was confused with the weird hostnames that I get when i try gethostbyaddr for different websites. So, I tried getting the ip of amazon using gethostbyname. Then I used the resulting IP in gethostbyaddr() but I did not get the hostname of amazon. I read the official documentation and it states that the alias list returned contains the alternative host names, but I still do not get www.amazon.com

So This is what I tried doing. socket.gethostbyname('www.amazon.com') And my result was: '13.35.134.162' Then I input this IP: socket.gethostbyaddr('13.35.134.162') But my result is: ('server-13-35-134-162.del54.r.cloudfront.net', [], ['13.35.134.162'])

Can someone explain why 'www.amazon.com' is not displayed and what is this hostname that I get?

Ad

Answer

The name you get back, if any at all, is dependent on how the network administrator setup their reverse dns.

If the reverse dns is setup, in my experience it is usually set to something more technical or dynamic rather than a simple name. The reason for this usually has to do with the fact that many sites may share an IP address and/or a site resolves to many IPs.

As such, instead of trying to reverse the IP to one of those site names, instead you'd reverse it to something that identifies that particular server.

Ad
source: stackoverflow.com
Ad