Query RootDSE using JNDI (Misc)
This code can be found in
Chapter 20 of Active Directory Cookbook, 2nd edition
Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.
Find out how to download all of the Misc code from this site.
/**
* Print the RootDSE for DC1
* usage: java RootDSE
*/
import javax.naming.*;
import javax.naming.directory.*;
class RootDSE {
public static void main(String[] args) {
try {
// Create initial context
DirContext ctx = new InitialDirContext();
// Read attributes from root DSE
Attributes attrs = ctx.getAttributes(
"ldap://DC1", new String[]{"*"});
// Get a list of the attributes
NamingEnumeration enums = attrs.getIDs();
// Print out each attribute and its values
while (enums != null && enums.hasMore()) {
String nextattr = (String)enums.next();
System.out.println( attrs.get(nextattr) );
}
// Close the context
ctx.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
|
This code has been viewed 1865 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|