ping之后获取计算机名称

ping之后获取计算机名称

本文介绍了ping之后获取计算机名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的代码,它完美无缺。它正在ping一系列IP地址并返回已启动的IP地址(带有主机变量)



但我还要检索找到的计算机名称IP地址。也许这很简单,但我无法在网上找到如何检索它。



  public   bool  Ping( string  host, int 次尝试, int  timeout)
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();

System.Net.NetworkInformation.PingReply pingReply;

for int i = 0 ; i < 尝试; i ++)
{
尝试
{
pingReply = ping.Send(host,timeout);

if (pingReply!= null &&
pingReply.Status == System.Net.NetworkInformation.IPStatus.Success)

listView1.Items.Add(host);

return true ;

}
catch
{
}


}
解决方案

So this is my code and it works perfect. It is pinging a range of IP addresses and returns the IP address that are up (with "host" variable)

But I want also retrieve the computer name of the found IP addresses. Maybe it is very simple but I could not find on the internet howto retrieve it.

public bool Ping(string host, int attempts, int timeout)
 {
     System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();

     System.Net.NetworkInformation.PingReply pingReply;

     for (int i = 0; i < attempts; i++)
     {
         try
         {
             pingReply = ping.Send(host, timeout);

             if (pingReply != null &&
                 pingReply.Status == System.Net.NetworkInformation.IPStatus.Success)

                 listView1.Items.Add(host);

                 return true;

         }
         catch
         {
         }


     }
解决方案


这篇关于ping之后获取计算机名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:23