Saturday, May 23, 2009

How to get IP Address by Java

import java.net.InetAddress;
public class GetIPAddress {

public static void main(String[] args) {
String ip = "";
try {
InetAddress inetAddress = InetAddress.getLocalHost();
ip = inetAddress.getHostAddress();
System.out.println("IP Address :: "+ip);
} catch (Exception e) {
e.printStackTrace();
}
}

}

3 comments:

  1. Hai,
    Thanks for the information.Suppose people dont have knowledge of java can find their ip address using the site www.ip-details.com.

    ReplyDelete
  2. Hai,
    Thanks. Its very simply umderstand that concept.

    ReplyDelete
  3. Hi,

    I am using the following code in my servlet to get the client's IP address.
    request.getRemoteAddr( )

    It is working well with 2000 and XP clients where as with Vista clients I am getting the IP address as "fe80:0:0:0: 591d:dea: 2c03:7e79" (IPv6 address). How to get the actual IP address (IPv4) from vista clients. Anybody please help me.

    Thanks in advance
    Y S Reddy

    ReplyDelete

Please put your feedback or your any question related to this blog. Thanks.