10

My problem is to match IP address to its hostname.

If the IP address is a public IP then a simple socket.gethostbyaddr(ip) solves it but my problem is with private IP i.e. IP of a network.

How can I get host names from a network IP address? Is there a way to find out hostname or not?

I'm trying to do this on Linux.

Mat
  • 202,337
  • 40
  • 393
  • 406
AjanShrestha
  • 545
  • 2
  • 5
  • 12
  • 1
    Search the site first. I don't know python but this looks like what you want: http://stackoverflow.com/questions/5576744/convert-ip-to-hostname – pachun May 25 '12 at 05:34
  • This question question is also identical: http://stackoverflow.com/questions/2575760/python-lookup-hostname-from-ip-with-1-second-timeout – ryucl0ud Aug 12 '12 at 17:02

1 Answers1

30

You've already got the Python code required

socket.gethostbyaddr(ip)

What you need is on the infrastructure side of things. To get an internal hostname, you need to query the internal DNS server for the network in question. Larger networks almost always have internal DNS services but some smaller network don't since they rely on other means (direct IP, NETBIOS, Bonjour, etc.) to find various resources.

TL:DR : You need to query the internal DNS services for the network in question

Mark
  • 1,449
  • 1
  • 13
  • 13