Tuesday, February 14, 2012

Getting IP address in java

try
{
InetAddress[] addresses = InetAddress.getAllByName( "http://wwwroboticsforall.blogspot.com/" /* Ip assress or Domain name */ );


for ( int i=0; i String hostname = addresses[i].getHostName();
               System.out.println(addresses[i].getHostAddress());
               System.out.println( hostname );

}
}


catch (UnknownHostException e)
{
System.out.println("unknown host");
}