Why Ping timeout is not working correctly?

后端 未结 3 1964
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-21 18:28

I have 5 pc and i want to ping this pc\'s are available or no. So I\'m using c# Ping class. Two pc are available but the other 3 pc are closed when i ping them my program wa

3条回答
  •  悲&欢浪女
    2020-12-21 18:40

    Pinging to IP Address like 8.8.8.8 worked absolutely fine, but when pinging to dns address like www.google.com give random time outs.
    i think these random time outs relates to dns resolution nothing to do with ping time outs

        private static bool DoPing()
        {
            try
            {
                using (System.Net.NetworkInformation.Ping ping = new Ping())
                {
    
                    PingReply result = ping.Send("8.8.8.8", 500, new byte[32], new PingOptions { DontFragment = true, Ttl = 32 });
    
                    if (result.Status == IPStatus.Success)
                        return true;
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }
    

提交回复
热议问题