Getting the IP Address and Hostname of the Local Machine
try {
InetAddress addr = InetAddress.getLocalHost();
// Get IP Address
byte[] ipAddr = addr.getAddress();
// Get hostname
String hostname = addr.getHostName();
} catch (UnknownHostException e) {
}
Good example. Thank you!
Gracias
Gracias!!!
danke szun!
This does not work on Virtual machines. Do we have any other robust way of finding machine information?
Genial!
fine code........
well, this gets 127.0.0.1 , what if i want to get 192.111.1.1 if i set my host ip to that ip?
I want to get the address of localhost, i mean 10.0.0.2, so that i can access it from other machines.
thanksss
try this:
String myString = addr.getHostAddress();
thank u !! :-)