-3

是否可以编写 C# 代码来测试远程服务器上的 Internet 连接?

例如,如果我使用 powerhsell 执行此操作,我会这样做:

Psexec \\MyWebServer ping www.google.com

谢谢

4

1 回答 1

1

您可以使用PingPingReply类并包括System.Net.NetworkInformation检查:

  Ping ping = new Ping();
  //PingReply reply= ping.Send("ip address");
  PingReply reply= ping.Send("www.google.com");


  if(reply.Status == IPStatus.Success)
    {
     // Connected 

       Console.WriteLine ("Address: {0}", reply.Address.ToString ());
       Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
       Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
       Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
       Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
    }
  else
    {
      Console.WriteLine (reply.Status);
    }

在这里查看更多详情

于 2013-05-24T11:35:05.947 回答