Csharp/C#教程:如何获取域控制器IP地址分享


如何获取域控制器IP地址

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

这是我怎么做的。

您需要使用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); 

谢谢大家,

我在这段代码中完成了它

  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); } 

再次感谢

那么这里是如何获得它的一般工作流程,如MS网站所述:

https://support.microsoft.com/kb/247811

以下是来自PInvoke.net的链接,用于调用引用的DsGetDcName函数:

https://pinvoke.net/default.aspx/netapi32/DsGetDcName.html

您可以按照第一个链接中的说明进行操作并执行原始DNS A记录查询,但我认为PInvoke调用应该可以解决问题。

希望有所帮助,

麦克风

上述就是C#学习教程:如何获取域控制器IP地址分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1015168.html

(0)
上一篇 2021年12月30日
下一篇 2021年12月30日

精彩推荐