Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Hostname from IP Address

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.

like image 319
AjanShrestha Avatar asked May 25 '12 05:05

AjanShrestha


1 Answers

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

like image 92
Mark Avatar answered Oct 22 '22 12:10

Mark