title: c# use Ping.send or sendAsync always successful even without network
body: <p>I was struggling with a problem for a long time. I was using unity and I want to ping my server and router. I was using UnityPing class at the beginning and it works fine for the most of devices, but when I testing on Google Pixel(Android 7.1) it always return -1. So I tried to use System.Net.NetworkInformation to ping my server. here is my code:</p>
  
  <pre><code>private void PingToServer()
  {
      AutoResetEvent waiter = new AutoResetEvent(false);
      System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();
      pingSender.PingCompleted += new PingCompletedEventHandler(PingCompletedCallback);
      string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
      byte[] buffer = Encoding.ASCII.GetBytes(data);
      int timeout = 10000;
      PingOptions options = new PingOptions(64, true);
      IPAddress address = IPAddress.Parse("119.81.194.57");
      pingSender.SendAsync(address, timeout, buffer, options, waiter);
  }
  private void PingCompletedCallback(object sender, PingCompletedEventArgs e)
  {
      if (e.Cancelled)
      {
          Console.WriteLine("Ping canceled.");
          ((AutoResetEvent)e.UserState).Set();
      }
      if (e.Error != null)
      {
          Console.WriteLine("Ping failed:");
          Console.WriteLine(e.Error.ToString());
          ((AutoResetEvent)e.UserState).Set();
      }
      PingReply reply = e.Reply;
      int pingTime = (int)reply.RoundtripTime;
      UnityEngine.Debug.Log(reply.RoundtripTime);
      ((AutoResetEvent)e.UserState).Set();
  }
  </code></pre>
  
  <p>And It always return a RoundripTime which seems like a number make sense, but when I try to ping another ip address which is not available to reach or even turn off the internet it always return a RoundripTime with reply.status equals to IPStatus.Success. Now I'm confused, did I really ping to my remote server or not?</p>
  
  <p>I did chekced some other similar questions, and it doesn't solved the problem. Some answers suggest to use SendPingAsync instead of SendAsync, but that is not possible for unity.</p>