0 votes
in JAVA by
How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?

1 Answer

0 votes
by
By InetAddress.getByName("192.18.97.39").getHostName() where 192.18.97.39 is the IP address. Consider the following example.

import java.io.*;    

import java.net.*;    

public class InetDemo{    

public static void main(String[] args){    

try{    

InetAddress ip=InetAddress.getByName("195.201.10.8");    

  

System.out.println("Host Name: "+ip.getHostName());    

}catch(Exception e){System.out.println(e);}    

}    

}
...