using
System;
using
System.Net;
using
System.Net.NetworkInformation;
class
Program
{
static
void
Main(
string
[] args)
{
int
count = 4;
IPAddress addr = IPAddress.Parse(
"220.181.111.86"
);
Ping ping =
new
Ping();
long
timeSum = 0;
int
succCount = 0;
//发送
Console.WriteLine(
"正在ping {0}"
, addr);
for
(
int
i = 0; i < count; ++i)
{
PingReply pr = ping.Send(addr);
if
(pr.Status == IPStatus.TimedOut)
Console.WriteLine(
"超时"
);
else
if
(pr.Status == IPStatus.Success)
{
Console.WriteLine(
"延时:{0}毫秒"
, pr.RoundtripTime);
++succCount;
timeSum += pr.RoundtripTime;
}
}
if
(timeSum != 0)
Console.WriteLine(
"平均延时{0}毫秒,丢包率{1}%"
, 1.0 * timeSum / succCount, (count - succCount) * 100.0 / count);
else
Console.WriteLine(
"丢包率100%"
);
return
;
}
}