The following example illustrates getting IP address in Java using InetAddress class.
getByName(args[0]): This static method of InetAddress class gets the IP address of the given host name which has to be in the format, google.com for example.
import java.net.*;
class GetIP
{
public static void main(String args[]) throws Exception
{
InetAddress i=InetAddress.getByName(args[0]);
System.out.println(new String(i.getHostAddress()));
}
}
No comments:
Post a Comment