【问题标题】:How can manual get ip address of a website throw Google DNS, OpenDNS... by send and receive packet如何通过发送和接收数据包通过 Google DNS、OpenDNS 手动获取网站的 IP 地址
【发布时间】:2011-09-05 14:57:12
【问题描述】:

我想写一个小程序来通过手动发送和接收来自Google DNS,Open DNS的数据包来获取一些网站的IP地址。

如何帮助我。

我写了这个但不能正常工作。

public static void main(String args[]) throws Exception
{
    String str="stackoverflow.com";
    DatagramPacket dp=new DatagramPacket(str.getBytes(),str.length());
    DatagramSocket ds=new DatagramSocket();

    dp.setAddress(InetAddress.getByName("8.8.8.8"));
    dp.setPort(53);

    ds.send(dp);
    System.out.println("SENDED");

    byte[] receive=new byte[1024];
    dp.setData(receive);

    System.out.println("PREPARING FOR RECEIVE : ");
    ds.receive(dp);

    System.out.println(new String(receive));
}

【问题讨论】:

    标签: java sockets dns ip packet


    【解决方案1】:

    如果您不想实现 DNS 协议,dnsjava 可能会让您感兴趣。

    【讨论】:

      【解决方案2】:

      您需要实现 DNS 协议 -- 起点可以是 https://www.rfc-editor.org/rfc/rfc1035

      【讨论】:

      • 如果您不熟悉 DNS 的工作方式,也可以看看维基百科:en.wikipedia.org/wiki/Domain_Name_System
      • 我知道,但我不知道发送到 dns 服务器的数据结构。你能帮我吗
      • 如果您是这个意思,我不会为您编写代码。我将首先查看@Thor 发布的 dnsjava 库,您很可能会在其中找到所需的结构。
      • 哦,非常感谢。我从不希望你为我写代码。我没有这个想法。
      【解决方案3】:

      DNS 协议在RFC 1034 中定义。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-29
        • 1970-01-01
        • 1970-01-01
        • 2011-10-18
        • 2015-05-20
        • 2015-12-19
        • 1970-01-01
        相关资源
        最近更新 更多