因为System.dll中发生SocketException而没有结果 [英] Getting no results because SocketException occurred in System.dll
本文介绍了因为System.dll中发生SocketException而没有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个应用程序,用于检索给定网络上所有计算机的名称和IP地址。这是为了在远程连接到计算机时使用的技术支持。我仍在开发并且只在我自己的网络上进行测试,但是当我运行它时,我没有得到任何结果,这显示在输出中。
I am writing an application that retrieves the names and IP addresses of all computers on a given network. This is for technical support to use while remoting into a computer. I'm still developing and only testing on my own network, but when I run it I get no results and this shows up in the output.
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
我的代码如下:
public List<NetworkComputer> getComputers( string domain )
{
List<NetworkComputer> computers = new List<NetworkComputer>();
DirectoryEntry entry = new DirectoryEntry( domain );
DirectorySearcher searcher = new DirectorySearcher( entry );
searcher.Filter = ("(objectClass=computer)");
searcher.SizeLimit = int.MaxValue;
searcher.PageSize = int.MaxValue;
foreach( SearchResult result in searcher.FindAll() )
{
if( result.GetDirectoryEntry().Name.StartsWith( "CN=" ) )
{
IPAddress ipAddress = null;
ipAddress = Dns.GetHostAddresses( result.GetDirectoryEntry().Name.Remove( 0, "CN=".Length ) )[0];
computers.Add( new NetworkComputer( result.GetDirectoryEntry().Name.Remove( 0, "CN=".Length ), ipAddress ) );
}
}
return computers;
}
}
}
如果我在不尝试的情况下运行它获取IP地址我得到一个没有问题的所有计算机的列表。这是造成我问题的IP地址。
If I run it without attempting to get IP addresses I get a list of all computers with no issues. It's the IP addresses that are causing me problems.
推荐答案
在这里查看这篇文章
这解释了问题的原因。
这篇关于因为System.dll中发生SocketException而没有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文