IP Address not obtained in java
Posted
by nilesh
on Stack Overflow
See other posts from Stack Overflow
or by nilesh
Published on 2009-06-30T06:33:06Z
Indexed on
2010/06/11
14:13 UTC
Read the original article
Hit count: 173
java
This code used to return my local ip address as 192.xxx.x.xxx but now it is returning 127.0.0.1 . Please help me why the same code is returning different value. Is there something that I need to watch at linux OS.
import java.util.*;
import java.lang.*;
import java.net.*;
public class GetOwnIP
{
public static void main(String args[]) {
try{
InetAddress ownIP=InetAddress.getLocalHost();
System.out.println("IP of my system is := "+ownIP.getHostAddress());
}catch (Exception e){
System.out.println("Exception caught ="+e.getMessage());
}
}
}
© Stack Overflow or respective owner