如何获取域控制器IP地址

net*_*eng 2 c# networking network-programming active-directory

如何以编程方式使用域控制器IP地址C#?

bar*_*ron 5

我就是这样做的.

您需要使用System.Net和System.DirectoryServices.

// get root of the directory data tree on a directory server
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://rootDSE");
// get the hostname of the directory server of your root (I'm assuming that's what you want)
string dnsHostname = dirEntry.Properties["dnsHostname"].Value.ToString();
IPAddress[] ipAddresses = Dns.GetHostAddresses(dnsHostname);
Run Code Online (Sandbox Code Playgroud)