Re: Active Directory DNS query

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Here is the sample code I have been given. I need to rewrite this in
VB as it is currently in java. I don't exactly understand what the
code is. The standards in our IS department require us to use the
method of querying
for AD servers. If anyone can explain to me what is going on in the
code and maybe some samples I can use to do this in VB, it would be
greatly appreciated. Someone has said something about how ADSI in VB
does this automatically. I am not sure what that means or what ADSI
is, so if you have an example of that, than that would be appreciated.


///////////////////////////////////////////////////////////////////////////­///////////

//
// This is an example of how DNS can be queried to find Active
Directory
//
//
// The results of this query should be sorted by the DNS records
weight,
// using the lowest weighted records first and the higher weighted
records
// last.
//
// To find Domain Controllers in a specific Active Directory site
// look for the following DNS SRV record format:
// Format: _ldap._tcp.<SITE NAME>.dc._msdcs.<DOMAIN NAME>.domain.com

//
// To find Global Catalogs in a specific Active Directory site
// look for the following DNS SRV record format:
// Format: _ldap._tcp.<SITE NAME>._sites.gc._msdcs.domain.com
//
///////////////////////////////////////////////////////////////////////////­////////////



import javax.naming.*;
import javax.naming.directory.*;
import java.util.*;


public class findad
{
public static void main( String args[] )
{
String domainController = null;
String dnsServiceName = "_ldap._tcp";
//Specifies a Global Catalog server
String aDSite = "<site>";
//The Active Directory SITE to look
String dnsDomain = "us.domain.com";
//The DNS base Zone to look
String aDDomain = aDSite +
"._sites.dc._msdcs." +
dnsDomain; //The DNS Zone to look
String dnsNameServer = "ad-dns.domain.com";
//The DNS server to query
String dnsQueryType[] = {"SRV"};
//DNS record type to query
String retDomainController = null;
//Returned Domain Controller
Long retDNSweight;
//Returned DNS record weight for the returned Domain Controller


try {
Hashtable dnsEnv = new Hashtable();
dnsEnv.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory");
dnsEnv.put("java.naming.provider.url", "dns://"
+ dnsNameServer +
"/" + aDDomain);
DirContext dnsContext = new
InitialDirContext(dnsEnv);
Attributes dnsQueryResult =
dnsContext.getAttributes(dnsServiceName,
dnsQueryType);
if (dnsQueryResult == null)
{
System.out.println("Returned NULL");
}
for (NamingEnumeration dnsRR =
dnsQueryResult.getAll();dnsRR.hasMoreElements();)
{
Attribute rr = (Attribute)dnsRR.next();

String attrId = rr.getID();
for (Enumeration vals =
rr.getAll();vals.hasMoreElements();)
{
domainController =
vals.nextElement().toString();


StringTokenizer st = new
StringTokenizer( domainController );
retDNSweight = new
Long(st.nextToken());
st.nextToken();
st.nextToken();
retDomainController =
st.nextToken();


System.out.println("Domain
Controller: " + retDomainController + "
Weight: " + retDNSweight.longValue());


retDomainController = null;
retDNSweight = null;
}
}
dnsContext.close();
} catch(Exception e) {
System.err.println("Error performing DNS lookup
for: " + aDDomain +
"\n" + e);
}
}

.



Relevant Pages

  • Remote Branch DC wont Replicate With Corporate DC
    ... Active Directory could not resolve the following DNS host name of the source ... domain controller to an IP address. ... 'Event' is not recognized as an internal or external command, ... operable program or batch file. ...
    (microsoft.public.windows.server.dns)
  • Re: GPOs Not Replicating
    ... Services could not resolve the following DNS host name of the source ... domain controller is running Active Directory Domain Services and is ... controller is using a valid DNS server for DNS services, ... Action Create an NTDS Site Settings object for this site. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Domain Controllers Cant reach Default Gateway...
    ... Making the ISA a domain controller would ... area of DNS it was missing the CNAME entry with the GUID ... DNS server doesn't support this feature. ... The problem is my XP Pro laptop. ...
    (microsoft.public.win2000.active_directory)
  • Re: Domain Controllers Cant reach Default Gateway...
    ... Making the ISA a domain controller would ... one of the domain controllers the active directory DNS zone ... DNS server doesn't support this feature. ... The problem is my XP Pro laptop. ...
    (microsoft.public.win2000.active_directory)