esupa
esupa

Reputation: 103

socket.gethostbyaddr() returns error on some computers and not for others

I've looked for any other threads related to this topic, but after an extensive search i was not able to find an answer that relates to my question. Using Python, I'm trying to use socket.gethostbyaddr("ip here") to determine the hostname of an ip address in a local network:

import socket

def gethostname(ip):
    hostname = socket.gethostbyaddr(ip)

    return hostname

For some computers (such as the server) this returns the triplet of hostname, alias and other IP's, but for others it does not. Instead, i get the following error:

socket.herror: [Errno 4] No address associated with name

What exactly does this error imply? What could it be that causes it? Is there any service or instane that should be running on the target computer in order for this to work? The computers i'm trying to get the hostname of run Debian.

If this question has already been asked then i am sorry, but i could not find it.

If it has something to do with reverse dns lookups, how would i solve this?

Upvotes: 0

Views: 1170

Answers (1)

Bart Friederichs
Bart Friederichs

Reputation: 33573

It means exactly what it says, there is no address associated. Not all IP addresses have a reverse-lookup address.

Upvotes: 2

Related Questions