【发布时间】:2014-09-08 15:40:34
【问题描述】:
我正在开发一个实用程序,用于管理指定目录根目录中指定域(不一定是运行应用程序的计算机所在的域)中的多台计算机。我遇到的问题是,一旦我从外部 AD OU 收集了计算机名称,由于 DNS,我无法根据计算机名称进行管理。如果提供了 DNS 服务器的 IP 和该域的凭据,是否可以在外部 DNS 服务器上执行 DNS 查找?
这是我用于初始化过程的代码(在同一域内工作)。非常感谢任何意见!
private Task InitializeComputers()
{
try
{
Computers.Clear();
object cLock = new object();
PrincipalContext context = new PrincipalContext(ContextType.Domain, CurrentConfiguration.LDAPAddress,
CurrentConfiguration.DirectoryRoot, ContextOptions.Negotiate,
CurrentConfiguration.AdminUser, CurrentConfiguration.AdminPassword);
ComputerPrincipal computer = new ComputerPrincipal(context);
computer.Name = "*";
PrincipalSearcher searcher = new PrincipalSearcher(computer);
PrincipalSearchResult<Principal> result = searcher.FindAll();
Parallel.ForEach(result, (r) =>
{
ComputerPrincipal principal = r as ComputerPrincipal;
DirectoryObject cObject = new DirectoryObject(CurrentConfiguration)
{
Name = principal.Name
};
lock (cLock)
{
Computers.Add(cObject);
}
});
}
... // Catch stuff here
}
private async Task InitializeConnections()
{
Task[] tasks = Computers.Select(x => x.CheckConnectionAsync()).ToArray();
await Task.WhenAll(tasks);
}
// This is where I need to be able to get the IP Address. Thoughts???
public Task CheckConnectionAsync()
{
return Task.Run(() =>
{
try
{
Ping PingCheck = new Ping();
PingReply Reply = PingCheck.Send(Name); // <--- need IP Address instead
if (Reply.Status == IPStatus.Success)
{
IsAvailable = true;
IPHostEntry host = Dns.GetHostEntry(Name); // Does not work for machines on different domain.
IPAddress = host.AddressList.FirstOrDefault().ToString();
}
else
{
IsAvailable = false;
IsWMIActive = false;
}
}
... // catch stuff here ...
});
}
【问题讨论】:
-
只需为这些远程计算机附加完整的域,例如
machine.domain.tld,dns 会自动去查询domain.tlddns 服务器。如果你只是做machine,那么它将查询machine.jamie_still_domain.tld -
我已经试了一下。当我尝试在 ping 之前执行 Dns.GetHostEntry(Name + "." + CurrentConfig.DomainName) 时,它仍然返回 Host Not Found SocketExcpetions。问题的另一部分是它位于封闭的企业网络上,无法为托管我的应用程序所在机器的 DNS 区域提出查找区域(尝试在可以访问的单独托管域上使用实验室虚拟机进行测试) IP,但不是 DNS 名称)。
-
我看了一下该线程,但想确保没有内置的 .NET 可以这样做,而不必为外部 DNS 请求构建新的命名空间或导入另一个库。感谢您的响应!
标签: c# dns remote-access