是否可以编写C#代码来测试远程服务器上的Internet连接?
例如,如果我使用powerhsell这样做,我会这样做:
Psexec \\ MyWebServer ping www.google.com
由于
答案 0 :(得分:1)
您可以使用Ping和PingReply课程并添加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);
}
查看here了解详情