Any help much appreciated.
Rich.
>How can I get a list of other machines connected
>to a Windows2000 local area network. I guess
>JNDI is the way to go, but which factory class
>do I need? and what is the incantation (PROVIDER_URL
>etc) to get it working
see http://mindprod.com/jglossj.html#JNDI
Read the tutorial. It is a very frustrating tutorial because it
refuses to use any concrete examples to explain what it is up to. It
is very mathematical and abstract. However, if you plod it will
eventually make sense.
Here is some code I use to get the DNS/MX records via JNDI.
The guts is the DirContext.getAttributes method.
/**
* Gets all matching dns records as an array of strings.
*
* @param domain domain, not site in that domain, for which you
want
* the DNS records.
*
* @param types e.g. new String {"MX","A"}
* to describe which types of record you want.
* @return ArrayList of Strings
*/
static ArrayList getDNSRecs (String domain, String[] types) throws
NamingException
{
ArrayList results = new ArrayList(15);
DirContext ictx = new InitialDirContext();
Attributes attrs = ictx.getAttributes("dns://" + dnsServer + "/"
+ domain,
types);
for ( Enumeration e = attrs.getAll(); e.hasMoreElements(); )
{
Attribute a = (Attribute) e.nextElement();
int size = a.size();
for ( int i=0; i<size; i++ )
{
// MX string has priority (lower better) followed by
associated mailserver
// A string is just IP
results.add(a.get(i));
} // end inner for
} // end outer for
return results;
}
--
Available for tutoring, problem solving or contract
programming for $50 US per hour. The Java glossary is at
http://www.mindprod.com/jgloss.html
or http://64.251.89.39/jagg.html
-
canadian mind products, roedy green
*******************************************************************
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.dns.DnsContextFactory");
env.put(Context.PROVIDER_URL,"dns:");
DirContext ictx = new InitialDirContext(env);
Attributes attrs = ictx.getAttributes("SEATTLE",new String[]{"A"});
*******************************************************************
I get this when I run it...
-------------------------------------------------------------------
javax.naming.CommunicationException: DNS error. Root exception is
java.net.SocketException: socket closed
at java.net.PlainDatagramSocketImpl.receive(Native Method)
at java.net.DatagramSocket.receive(DatagramSocket.java:392)
at com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:321)
at com.sun.jndi.dns.DnsClient.query(DnsClient.java:162)
at com.sun.jndi.dns.Resolver.query(Resolver.java:52)
at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:346)
at
com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:216)
at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:124)
at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:112)
at
javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:124)
at KTTTest.attr(KTTTest.java:191)
at KTTTest.main(KTTTest.java:104)
---------------------------------------------------------------------
Do you know. I think I haven't got a DNS server? But my LAN works fine.
Rich.
Roedy Green wrote: