【问题标题】:In C# how do I get the list of local computer names like what one gets viewing the Network in windows explorer在 C# 中,如何获取本地计算机名称列表,例如在 Windows 资源管理器中查看网络
【发布时间】:2011-07-31 16:03:42
【问题描述】:

关于获取本地机器的名称和 IP 地址有很多问题,还有一些关于获取 LAN 上其他机器的 IP 地址的问题(并非所有问题都正确回答)。这是不同的。

在 Windows 资源管理器中,如果我选择侧栏上的网络,我会看到按机器名称列出的 LAN 上的本地机器(无论如何,在 Windows 工作组中)。如何在 C# 中以编程方式获取相同的信息?

【问题讨论】:

标签: c# windows lan workgroup


【解决方案1】:
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;
}

【讨论】:

【解决方案2】:

您可以尝试使用System.DirectoryServices 命名空间。

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);
        }
    }
}

【讨论】:

    【解决方案3】:

    您需要为给定范围内的所有 IP 广播 ARP 请求。首先在您的网络上定义基本 IP,然后设置一个上位标识符。

    我本来打算写一些代码示例等,但看起来有人在这里全面介绍了这一点;

    Stackoverflow ARP question

    【讨论】:

      【解决方案4】:

      这似乎是你所追求的:How get list of local network computers?

      在 C# 中:您可以使用 Gong 解决方案 外壳库 (https://sourceforge.net/projects/gong-shell/)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-05
        • 2011-02-03
        • 2023-04-03
        • 2013-04-25
        • 2010-10-14
        • 2013-08-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多