【问题标题】:c# Howto enumerate DCs in a different domainc# 如何枚举不同域中的 DC
【发布时间】:2012-03-06 08:49:33
【问题描述】:

我想枚举域中的所有 DC(当前用户或计算机是其中的成员,也不在同一个林中)。

我发现了这个不错的方法

Domain domain = Domain.GetCurrentDomain();
foreach (DomainController dc in domain.DomainControllers)
   ...

但是,我不知道如何远程连接到 获取正确的域上下文。

通过连接

DirectoryEntry child = new DirectoryEntry("LDAP://" + server + "/" + objectDn, userName, password);

效果很好。但我不知道如何将它们组合在一起。

【问题讨论】:

  • 解决方案已经在stackoverflow.com/questions/323608/… Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, "yourDomain", "username", "password"));
  • 差不多。但这不允许将 IP 地址传递到应执行请求的位置!它需要在同一个森林中的域。
  • 只需将类型更改为目录服务器,如果我遗漏了问题 System.DirectoryServices.ActiveDirectory.DirectoryContext dc = new DirectoryContext(DirectoryContextType.DirectoryServer, "", "your用户名", "密码");

标签: c# domaincontroller


【解决方案1】:
using System.DirectoryServices.ActiveDirectory;

...
....

DirectoryContext dc = new DirectoryContext(DirectoryContextType.DirectoryServer, "ip", "user", "pwd"); //change parameters here
Forest forest = Forest.GetForest(dc);    
Console.WriteLine(forest.Domains.Count); 

以上对我有用(给出正确的域数)

显然,我正在使用网络管理员帐户进行测试。希望这会有所帮助

【讨论】:

  • 效果很好,谢谢。我稍微修改了一下,让域直接脱离域上下文而不是森林。
猜你喜欢
  • 1970-01-01
  • 2010-11-26
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 2011-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多