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)?
Thanks, but I have to implement this functionality in an existing program, so I cannot use nmap
melculetz
2009-06-08 14:35:19
You can however look at how Nmap does it and reimplement that method in C#...
Moo
2009-06-08 15:09:17
nmap's the only solution that will work... Can be called from C# just fine!(Surely .NET programmers can call other programs)
Arafangion
2009-06-18 06:39:30
+1
A:
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.
Hooloovoo
2009-06-08 14:50:18
Does that work for hosts with a static IP address and have not registered a dynamic DNS address?
Arafangion
2009-06-18 06:38:51
How? The only possible way I can think of that this would be true is if _all_ of those machines were part of the domain, which is not necessarily the case.
Arafangion
2009-06-18 23:24:02
Read the question - all the machines are on the same domain. This assumes a DNS server is available and contactable.
Hooloovoo
2009-06-19 07:39:46
+1
A:
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.
Kevin Loney
2009-06-08 15:06:57