Ping pingSender = new Ping();
PingOptions options = new PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send("222.111.111.111", timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
i = 0;
Console.WriteLine("IP地址: {0}", reply.Address.ToString());
Console.WriteLine("返回时间: {0}", reply.RoundtripTime);
}
看返回时间