Who is my DNS Server?

R

Roedy Green

To use DirContext.getAttributes to get at MX records you need to know
the name or IP of a nearby DNS server. Is there a way now to get one
dynamically or do I still have have to configure one in?


"Never in human history have such genocide and cruelty been witnessed.
Such a genocide was never seen in the time of the pharaohs nor of Hitler
nor of Mussolini."
~ Mehmet Elkatmi, head of Turkish parliament's human rights commission
on Bush's atrocities in the Iraq war.
 
S

Sudsy

Roedy said:
To use DirContext.getAttributes to get at MX records you need to know
the name or IP of a nearby DNS server. Is there a way now to get one
dynamically or do I still have have to configure one in?

AFAIK, you either have to use a protocol like DHCP or specify your
nameservers in /etc/resolv.conf. Alternatives don't make a lot of
sense to me...
 
T

Thomas Schodt

Tom said:
I think he's trying to get the DNS server as assigned to his (local OS)
TCP/IP stack as opposed to typing it in manually.

That is what the example I found does.

Well, you don't "get" the DNS server IP or name.
But you do get your MX query fulfilled, so it must use the DNS server
known by your local TCP/IP stack.

Here's a small class I wrote to verify that.

import java.util.Enumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class GetMX {
public static void main(String[] arg) throws Exception {
String host = arg[0];
DirContext ictx = new InitialDirContext();
Attributes attrs = ictx.getAttributes("dns:/" + host,
new String[]{"MX"});
Attribute att = attrs.get ("MX");
for (Enumeration i = att.getAll(); i.hasMoreElements(); ) {
Object o = i.nextElement();
System.out.println(o.toString());
}
}
}
 
T

Tom Dyess

Thomas Schodt said:
Tom said:
I think he's trying to get the DNS server as assigned to his (local OS)
TCP/IP stack as opposed to typing it in manually.

That is what the example I found does.

Well, you don't "get" the DNS server IP or name.
But you do get your MX query fulfilled, so it must use the DNS server
known by your local TCP/IP stack.

Here's a small class I wrote to verify that.

import java.util.Enumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class GetMX {
public static void main(String[] arg) throws Exception {
String host = arg[0];
DirContext ictx = new InitialDirContext();
Attributes attrs = ictx.getAttributes("dns:/" + host,
new String[]{"MX"});
Attribute att = attrs.get ("MX");
for (Enumeration i = att.getAll(); i.hasMoreElements(); ) {
Object o = i.nextElement();
System.out.println(o.toString());
}
}
}

Ah! Seems like a very nice solution.
 
R

Roedy Green

AFAIK, you either have to use a protocol like DHCP

I then have to roll my own DHCP protocol to find out the server?

I am hoping for something novices could use who have no idea what a
DNS server is.


"Never in human history have such genocide and cruelty been witnessed.
Such a genocide was never seen in the time of the pharaohs nor of Hitler
nor of Mussolini."
~ Mehmet Elkatmi, head of Turkish parliament's human rights commission
on Bush's atrocities in the Iraq war.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top