• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DNS query, protocol

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I want to create a simple java console application that queries a DNS server.
I dont want to use libraries like dnsjava or anything else.
I want to use datagrams.
Can anyone help me with this.

the problem is that i don't know how the message in the below code should look like.
How DNS query should llok like.


import java.net.*;
class DatagramTest
{
public static void main(String[] args)
throws Exception
{
DatagramSocket socket;
DatagramPacket packet;
InetAddress address;
byte[] message = new byte[256];
int port = 13;

socket = new DatagramSocket();
address = InetAddress.getByName("*****");
packet = new DatagramPacket(message, message.length,
address, port);
socket.send(packet);

packet = new DatagramPacket(message,
message.length);
socket.receive(packet);
String received = new String(packet.getData(), 0);
System.out.println("Received: " + received);
socket.close();
}
}


Thanks in advance!
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

That's quite a project you've picked up for yourself, especially considering the fact that you indicate you have no real knowledge about how DNS actually works. (Don't worry about that, neither do I ) Can you tell us why you don't want to use an existing library?

Anyway, the first step would be to research how the DNS protocol works. I've checked this briefly but it only mentions that UDP is used. Perhaps you can find more information from the references at the bottom of that page.

And could you please UseCodeTags next time? It makes code easier to read.
 
Kovacs Zsolt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the answer. I want to do this because I have to . It is an assigment at the University.
And sorry for the CodeTags. Anyway if i figure out i post it maybe help someone someday.
There is so little information about this on the net
 
Marshal
Posts: 28244
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know even less about DNS than Rob does (apparently we both know what it is, but that's all). So I chose "dns protocol" as my google keywords and soon found a few documents which look like they might be what you need. Here's one of them: DNS Protocol; in addition there seem to be other more basic documents in the same set of pages.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic