c#实现ping功能的函数代码

public static string PingResult(string ip)
        
{
            System.Net.NetworkInformation.Ping p 
= new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingOptions options 
= new System.Net.NetworkInformation.PingOptions();
            options.DontFragment 
= true;
            
string data = "aa";
            
byte[] buffer = Encoding.ASCII.GetBytes(data);
            
//Wait seconds for a reply.
             int timeout = 1000 ;

            System.Net.NetworkInformation.PingReply reply 
= p.Send(ip, timeout, buffer, options);
            
return reply.Status.ToString();

        }

 

posted on 2008-05-20 09:21  Love↗钰珂  阅读(1053)  评论(0)    收藏  举报

导航