The class InetAddress under java.net package is helpful to retrieve some important host specific details such as IP address, host name and etc
Here is code snippet which does this. This might be useful for somebody.
import java.net.InetAddress;
import java.net.UnknownHostException;
public class HostNameAndAdress {
public static void main (String args[]){
try {
InetAddress addr = InetAddress.getLocalHost();
// Get IP Address
byte[] ipAddr = addr.getAddress();
// Get hostname
String hostName = addr.getHostName();
String fullyQualifiedHostName = addr.getCanonicalHostName() ;
String hostAddress = addr.getHostAddress() ;
System.out.println("Host Name : "+hostName) ;
System.out.println("Host IP Address : "+hostAddress) ;
System.out.println("Host Name with domain name suffix : " + fullyQualifiedHostName) ;
} catch (UnknownHostException e) {
e.printStackTrace() ;
}
}
}