Although, to my knowledge it isn't documented, I found that it works by
simply setting the port to the default LDAPS port which is 636. Not
suprisingly, Microsoft's documentation doesn't even describe what the URL
syntax is for using DirectoryEntry with non-Active Directory LDAP servers.
using System;
using System.DirectoryServices;
namespace LdapSearch {
public class LdapSearch {
public static void Main(string [] args) {
try {
if(args.Length != 6) {
Console.WriteLine("LdapSearch host port user password baseDN filter");
return;
}
string host = args[0];
string port = args[1];
string user = args[2];
string password = args[3];
string baseDN = args[4];
string filter = args[5];
DirectoryEntry de = new DirectoryEntry("LDAP://" + host + ":" + port + "/" +
baseDN);
de.Username = user;
de.Password = password;
de.AuthenticationType = AuthenticationTypes.FastBind;
DirectorySearcher ds = new DirectorySearcher(de, filter);
SearchResultCollection src = ds.FindAll();
foreach(SearchResult sr in src) {
Console.WriteLine(sr.Path);
foreach(string s in sr.Properties.PropertyNames) {
Console.Write(s + ":");
foreach(object o in sr.Properties) {
Console.Write(" " + o);
}
Console.WriteLine();
}
}
}
catch(Exception e) {
Console.WriteLine(e);
}
}
}
}
Jon
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.