In C #, how do I get a list of local computer names, like what you are browsing on a network in Windows Explorer

There are many questions about getting the name and IP addresses of the local computer and a few about getting the IP addresses of other computers on the local network (not everyone answered correctly). This is different.

In Windows Explorer, if I select Network in the sidebar, I get an idea of ​​the local machines on the local network, listed by machine name (in any case, in the Windows workgroup). How to get the same information programmatically in C #?

+7
source share
4 answers

You can try using the System.DirectoryServices namespace.

var root = new DirectoryEntry("WinNT:"); foreach (var dom in root.Children) { foreach (var entry in dom.Children) { if (entry.Name != "Schema") { Console.WriteLine(entry.Name); } } } 
+9
source

You need to broadcast the ARP request for all IP addresses within a given range. Start by determining the base IP address on your network and then setting the top identifier.

I was going to write some code examples, etc., but it looks like someone here has covered this in detail;

Stack ARP question

+3
source

This is similar to what you need: How to get a list of computers on a local network?

In C #: you can use the Gong Solutions Shell ( https://sourceforge.net/projects/gong-shell/ )

+2
source
 public List<String> ListNetworkComputers() { List<String> _ComputerNames = new List<String>(); String _ComputerSchema = "Computer"; System.DirectoryServices.DirectoryEntry _WinNTDirectoryEntries = new System.DirectoryServices.DirectoryEntry("WinNT:"); foreach (System.DirectoryServices.DirectoryEntry _AvailDomains in _WinNTDirectoryEntries.Children) { foreach (System.DirectoryServices.DirectoryEntry _PCNameEntry in _AvailDomains.Children) { if (_PCNameEntry.SchemaClassName.ToLower().Contains(_ComputerSchema.ToLower())) { _ComputerNames.Add(_PCNameEntry.Name); } } } return _ComputerNames; } 
0
source

All Articles