请告诉我如何使用c#获取局域网中连接的电脑的IP地址

发布于 2024-12-16 00:25:23 字数 315 浏览 4 评论 0原文

可能的重复:
列出所有已连接计算机的 IP 地址到单个 LAN

谁能确切地告诉我如何获取 LAN 中连接的 PC 的 IP 地址列表吗? 我厌倦了谷歌搜索,因为答案非常令人困惑。

请告诉我如何使用 C# 准确获取 IP 地址列表。

Possible Duplicate:
List the IP Address of all computers connected to a single LAN

Can anyone please tell me exactly how to get the list of IP addresses of the PCs connected in a LAN?
I got tired googling it because the answers are very confusing.

Please tell me how to exactly get the list of ip addresses using c#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱暴击 2024-12-23 00:25:23

这样您就可以选择特定的地址类型

IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
    if (ip.AddressFamily.ToString() == AddressFamily.InterNetwork)
    {
        localIP = ip.ToString();
    }
}
return localIP;

so you can select the specific address-types

IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
    if (ip.AddressFamily.ToString() == AddressFamily.InterNetwork)
    {
        localIP = ip.ToString();
    }
}
return localIP;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文