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));
}
you will need to implement the DNS protocol -- a starting point could be https://www.rfc-editor.org/rfc/rfc1035