주어진 네트워크의 모든 컴퓨터 이름과 IP 주소를 검색하는 응용 프로그램을 작성하고 있습니다. 이 기능은 컴퓨터에 원격으로 연결하는 동안 사용할 기술 지원용입니다. 나는 여전히 개발 중이며 내 네트워크에서만 테스트하고 있지만 실행하면 결과가 나타나지 않으며 결과가 출력됩니다. 다음과 같이System.dll에서 SocketException이 발생했기 때문에 결과가 나타나지 않습니다.
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
내 코드입니다 : 내가 문제없이 모든 컴퓨터의 목록을 IP 주소를 얻기 위해 시도하지 않고 그것을 실행하면
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 주소입니다.
[SocketException : address가 요청한 프로토콜과 호환되지 않습니다] 가능한 복제본 (http://stackoverflow.com/questions/2370388/socketexception-address-incompatible-with-requested-protocol) –