I want to pass some IP address, preferably as string how can I do it for domain ?
Using C#. Needed for Directory services.
private Domain domain;
I want to pass some IP address, preferably as string how can I do it for domain ?
Using C#. Needed for Directory services.
private Domain domain;
Domains do not have IP addresses.
Suppose you have an IP address for a workstation that belongs to a domain. You can find out the domain to which the workstatio belongs and then run LDAP queries against it.
//using System.Management;
private static string getWorkstationDomain(string workstationName)
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(@"\\workstationName\root\CIMV2",
"SELECT * FROM Win32_ComputerSystem");
var results = searcher.Get();
var domain = results
.OfType<ManagementObject>()
.Select(mo => (string)mo.Properties["Domain"].Value)
.FirstOrDefault();
return domain;
}
You can then connect to this domain to run LDAP queries:
DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://" + domain);