【发布时间】: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