Is there any way to programatically (in c#) get all the other workstations that are in the same domain/subnetwork as my computer and display some information about them (if they are active, what kind of OS they have installed, their IP etc)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is a VB solution, but I'm pretty sure you'll be able to make the changes you need to make this work!
There's probably a better way, but this was a first cut.
Imports System.Net.NetworkInformation
Imports System.Directory Services
Class NetworkInfo
Function GetComputers() as list(Of String)
dim List as new list(of String)
Dim DomainEntry as new DirectoryEntry("WinNT://" + DomainInfo.GetDomain.Trim())
DomainEntry.Children.SchemaFilter.Add("computer")
For Each Machine as DirectoryEntry in DomainEntry.Children
List.Add(Machine.Name)
Next
return List
End Function
End Class
There are all sorts of useful tools knocking about in the System.Net.NetworkInformation namespace to let you capture things like the IP address, etc.
回答2:
nmap does this plus a ton more. Its open source.
回答3:
The simplest approach that I can think of (which is far from fool proof) is to send an ICMP echo request (defined in RFC 792) to 224.0.0.1. C# provides the Ping class to do this. Keep in mind though that you run the risk of dropped packets, there is also the question as to whether or not all the machines on the network support multicast.