如何从本地LAN获取所有IP地址和计算机名称

问题描述:

如何从本地局域网获取所有IP地址和计算机名。



我等待你的回复



请帮助我谢谢



旧问题标题:Balakrishnan Dhinakaran我需要你的帮助

how to get all IP addresses and computernames from Local LAN.

I am waiting for your reply

Please help me thank you

Old Question title : Balakrishnan Dhinakaran I need your help

http://www.dijksterhuis.org/finding -the-local-ip-addresses-in-c / [ ^ ]



http://*.com/questions/151231/how-do-i-get-the- local-network-ip-address-of-a-computer-programmingmatically-c [ ^ ]


string myHost = System.Net.Dns.GetHostName();

                 System.Net.IPHostEntry myIPs = System.Net.Dns.GetHostEntry(myHost);

                 // Loop through all IP addresses and display each 

                 foreach (System.Net.IPAddress myIP in myIPs.AddressList)
                 {
listBox2.Items.Add (myIP.ToString());





[edit]已添加的代码块[ / edit]


private List<string> GetIpAddressFromHostName(List<string> ListHostNames)
        {
            List<string> ListIpAddress = new List<string>();

            foreach (var a in ListHostNames)
            {
                IPAddress[] ips;

                try
                {
                    ips = Dns.GetHostAddresses(a);

                    foreach (IPAddress ip1 in ips)
                    {
                        if (ip1.ToString().StartsWith("192.168."))
                        {
                            ListIpAddress.Add(ip1.ToString());
                        }
                    }
                }
                catch
                { 
                }
            }
            return ListIpAddress;
        }