用InetAddress的类方法:
public static InetAddress getByName(String host)
                             throws UnknownHostException
比如:
String ip="123.456.789.123";
try
{
    InetAddress ia=InetAddress.getByName(ip);
}
catch(UnknownHostException e)
{}
这样就可以了。

解决方案 »

  1.   

    还是这样好些:
    String ip="123.456.789.123";
    InetAddress ia=null;
    try
    {
        ia=InetAddress.getByName(ip);
    }
    catch(UnknownHostException e)
    {}
      

  2.   

    host不是主机名吗?用ip也可以?
      

  3.   

    可以,你去看看java的api文档吧。
      

  4.   

    我给你贴出来吧
    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.
      

  5.   

    这个:
    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.