从 LAN 中的主机名获取 IP 地址 [英] Get IP address from hostname in LAN

查看:34
本文介绍了从 LAN 中的主机名获取 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了很多关于如何通过 IP 地址获取主机名的示例,如何获取局域网中主机的 IP 地址?

I found many samples on how to get a hostname by an IP address, how can I get the IP address of a host in the LAN?

推荐答案

试试这个

public static void DoGetHostAddresses(string hostname)
{

   IPAddress[] ips;

    ips = Dns.GetHostAddresses(hostname);

    Console.WriteLine("GetHostAddresses({0}) returns:", hostname);

    foreach (IPAddress ip in ips)
    {
        Console.WriteLine("    {0}", ip);
    }
}

我从 http://msdn.microsoft.com/en-us/library/system.net.dns.gethostaddresses.aspx

这篇关于从 LAN 中的主机名获取 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆