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

So This is what I tried doing. socket.gethostbyname('') And my result was: '' Then I input this IP: socket.gethostbyaddr('') But my result is: ('', [], [''])

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



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.