首页 > 解决方案 > C# - 网络设备列表

问题描述

我应该显示本地网络中的所有笔记本电脑。我试过这个:

public static int GetAllIP(string[] args = null)
{
    string strHostName = new string("");
    if (args.Length == 0) {
        strHostName = DNS.GetHostName();
        Console.WriteLine("Local Machine's Host Name: " + strHostName);
    } else {
        strHostName = args[0];
    }
    IPHostEntry ipEntry = DNS.GetHostByName(strHostName);
    IPAddress[] addr = ipEntry.AddressList;

    int i = 0;
    while (i < addr.Length) {
        Console.WriteLine("IP Address {0}: {1} ", i, addr(i).ToString());
        System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
    }
    return 0;
}

我也试过这个也不行。我的意思是,我总是得到一个空数组。

任何其他想法如何做到这一点?

标签: c#wpflocal-network

解决方案


推荐阅读