Reputation: 1971
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)?
Upvotes: 1
Views: 1626
Reputation: 7553
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.
Upvotes: 1
Reputation: 2181
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.
Upvotes: 1