用InetAddress的类方法:
public static InetAddress getByName(String host)
throws UnknownHostException
比如:
String ip="123.456.789.123";
try
{
InetAddress ia=InetAddress.getByName(ip);
}
catch(UnknownHostException e)
{}
这样就可以了。
public static InetAddress getByName(String host)
throws UnknownHostException
比如:
String ip="123.456.789.123";
try
{
InetAddress ia=InetAddress.getByName(ip);
}
catch(UnknownHostException e)
{}
这样就可以了。
String ip="123.456.789.123";
InetAddress ia=null;
try
{
ia=InetAddress.getByName(ip);
}
catch(UnknownHostException e)
{}
InetAddress 类里:
getByName
public static InetAddress getByName(String host)
throws UnknownHostExceptionDetermines the IP address of a host, given the host's name. The host name can either be a machine name, such as "java.sun.com", or a string representing its IP address, such as "206.26.48.100".
Parameters:
host - the specified host, or null for the local host.
Returns:
an IP address for the given host name.
Throws:
UnknownHostException - if no IP address for the host could be found.
getByName
public static InetAddress getByName(String host)
throws UnknownHostExceptionDetermines the IP address of a host, given the host's name. The host name can either be a machine name, such as "java.sun.com", or a string representing its IP address, such as "206.26.48.100".Parameters:
host - the specified host, or null for the local host.Returns:
an IP address for the given host name.Throws:
UnknownHostException - if no IP address for the host could be found.