18 October 2012

How To Get IP Address for Logging In Java


InetAddress thisIp = null;
try {
thisIp = InetAddress.getLocalHost();

// Get IP Address
   byte[] ipAddr = thisIp.getAddress();

   // Get hostname
   String hostname = thisIp.getHostName();

   System.out.println("Local host IP :"+thisIp.getHostAddress());
   System.out.println("getAddress : "+ipAddr);
   System.out.println("getHostName : "+hostname);
 
} catch (UnknownHostException e1) {
e1.printStackTrace();
}