Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Lewis Evans   on Dec 03 In Java Category.

  
Question Answered By: Silk Choco   on Dec 03

Well 1 I use the following code snippet to get ip :

private String getIP()
{
// This try will give the Public IP Address of the Host.
try
{
URL url = new URL("http://automation.www.example.com/n09230945.asp");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String ipAddress = new String();
ipAddress = (in.readLine()).trim();

if (!(ipAddress.length() > 0))
{
try
{
InetAddress ip = InetAddress.getLocalHost();
System.out.println((ip.getHostAddress()).trim());
return ((ip.getHostAddress()).trim());
}
catch(Exception ex)
{
return "ERROR";
}
}
System.out.println("IP Address is : " + ipAddress);


External ip address can be obtained via http://www.ip-details.com/ too .

Share: 

 
 
Didn't find what you were looking for? Find more on IP numbers Or get search suggestion and latest updates.


Tagged: