In C# how do I get the list of local computer names like what one gets viewing the Network in windows explorer
Asked Answered
A

4

8

There are a lot of questions about getting the name and IP addresses of the local machine and several about getting IP addresses of other machines on the LAN (not all answered correctly). This is different.

In windows explorer if I select Network on the side bar I get a view of local machines on my LAN listed by machine name (in a windows workgroup, anyway). How do I get that same information programatically in C#?

Arbitration answered 7/4, 2011 at 12:38 Comment(1)
Have a look at this solution: #2558051Passel
P
11

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);
        }
    }
}
Passel answered 7/4, 2011 at 12:51 Comment(0)
B
3

You need to broadcast an ARP request for all IPs within a given range. Start by defining the base IP on your network and then setting an upper identifier.

I was going to write up some code examples etc but it looks like someone has covered this comprehensively here;

Stackoverflow ARP question

Behoof answered 7/4, 2011 at 12:52 Comment(0)
B
2

This seems to be what you are after: How get list of local network computers?

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

Biggerstaff answered 7/4, 2011 at 12:49 Comment(0)
F
0
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;
}
Follmer answered 19/6, 2016 at 5:36 Comment(1)
please follow thus [URL]( stackoverflow.com/help) it will be useful to raise your content quality upSchnitzler

© 2022 - 2024 — McMap. All rights reserved.