Convert Ip to Hostname

converting an IP address to host name

If you are coding in Java, try using InetAddress

InetAddress addr = InetAddress.getByName("173.194.36.37");
String host = addr.getHostName();
System.out.println(host);

Get Hostname from IP Address

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

How to get hostname from IP (Linux)?

In order to use nslookup, host or gethostbyname() then the target's name will need to be registered with DNS or statically defined in the hosts file on the machine running your program. Yes, you could connect to the target with SSH or some other application and query it directly, but for a generic solution you'll need some sort of DNS entry for it.



Related Topics



Leave a reply



Submit