如何通过发送和接收数据包手动获取网站的 IP 地址抛出 Google DNS、OpenDNS...
我想编写一个小程序,通过手动从 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));
}
I want write a small program to get IP Address of some websites by manual send and receive data packet from Google DNS, Open DNS.
How can help me.
I wrote this but not work properly.
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));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不想实现 DNS 协议,您可能会对 dnsjava 感兴趣。
If you don't want to implement the DNS protocol, dnsjava may interest you.
你需要实现 DNS 协议——起点可以是 https://www.rfc -editor.org/rfc/rfc1035
you will need to implement the DNS protocol -- a starting point could be https://www.rfc-editor.org/rfc/rfc1035
DNS 协议在 RFC 1034 中定义。
The DNS protocol is defined in RFC 1034.