程序里面想实现这样的功能,输入域名之后,解析出对应ip,应该如何做?

解决方案 »

  1.   

    java的api有没有还真没有留意过,你可以查看一下java的api document,如果没有你可以用java调用windows ping命令来给与实现。
      

  2.   

    我想在j2me中使用,ping的方法肯定不行
      

  3.   

    解析域名是DNS服务器干的事,如果你无法连到DNS服务器上去的话,就要自己维护域名/IP数据了。
      

  4.   

    ping www.sina.com.cnPinging jupiter.sina.com.cn [61.172.201.194] with 32 bytes of data:Reply from 61.172.201.194: bytes=32 time=3ms TTL=248
    Reply from 61.172.201.194: bytes=32 time=3ms TTL=248
    Reply from 61.172.201.194: bytes=32 time=3ms TTL=248
    Reply from 61.172.201.194: bytes=32 time=3ms TTL=248Ping statistics for 61.172.201.194:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 3ms, Maximum = 3ms, Average = 3ms
      

  5.   

    这个你要查一下DNS的协议文档
    通过DNS服务器来查找
      

  6.   

    有的,我给你们吧.import java.net.*;public class NetTool {
    InetAddress myIPaddress = null; InetAddress myServer = null; public static void main(String args[]) {
    NetTool mytool;
    mytool = new NetTool();
    System.out.println("Your host IP is: " + mytool.getMyIP());
    System.out.println("The Server IP is :" + mytool.getServerIP()); } // 取得LOCALHOST的IP地址
    public InetAddress getMyIP() {
    try {
    myIPaddress = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
    }
    return (myIPaddress);
    } // 取得 www.abc.com 的IP地址
    public InetAddress getServerIP() {
    try {
    myServer = InetAddress.getByName("www.abc.com");
    } catch (UnknownHostException e) {
    }
    return (myServer);
    }}
      

  7.   

    <html>
    fdsafsdafdasfads
    </html>
      

  8.   

    网络编程中的InetAddress类中的InetAddress.getByName()和InetAddress.getAllByName()都能将域名解析为IP地址:
    import java.net.*;
    public class Kkkk
    {
        public static void main(String args[])throws Exception
         {
             InetAddress address=InetAddress.getByName("Claire");//Claire是我的计算机名
             System.out.println(address);
             System.out.println("-----");
             InetAddress address1=InetAddress.getLocalHost();
             System.out.println(address1);
             InetAddress[] addresses=InetAddress.getAllByName("http://www.baidu.com");
            for(InetAddress addr:addresses)
             {
                 System.out.println(addr);
             }
         }
    }运行结果为:
    Claire/59.73.131.125
    -----
    Claire/59.73.131.125
    http://www.baidu.com/221.238.203.46