如何以编程方式获取域控制器 IP 地址C#
?
netseng
问问题
12727 次
3 回答
6
这就是我将如何做到的。
您需要使用 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);
于 2009-01-29T17:54:34.767 回答
3
谢谢大家,
我按照这段代码完成了
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.DirectoryServices.AccountManagement;
using System.DirectoryServices.ActiveDirectory;
public doIt()
{
DirectoryContext mycontext = new DirectoryContext(DirectoryContextType.Domain,"project.local");
DomainController dc = DomainController.FindOne(mycontext);
IPAddress DCIPAdress = IPAddress.Parse(dc.IPAddress);
}
再次感谢
于 2009-02-07T12:47:42.647 回答
1
好吧,这里是如何获取它的一般工作流程,如 MS 站点所述:
http://support.microsoft.com/kb/247811
这是来自 PInvoke.net 的链接,用于调用引用的DsGetDcName函数:
http://pinvoke.net/default.aspx/netapi32/DsGetDcName.html
您可以按照第一个链接中的描述进行原始 DNS A 记录查询,但我认为 PInvoke 调用应该可以解决问题。
希望有帮助,
麦克风
于 2009-01-29T17:00:53.190 回答