美文网首页
PING 检测延迟

PING 检测延迟

作者: 久百一 | 来源:发表于2020-08-19 20:04 被阅读0次

    public static int GetDey(string ipStr)
    {
    //构造Ping实例bai
    Ping pingSender = new Ping();
    //Ping 选项设置
    PingOptions options = new PingOptions();
    options.DontFragment = true;
    //测试数据du
    string data = "";
    byte[] buffer = Encoding.ASCII.GetBytes(data);
    //设置超时时间zhi
    int timeout = 120;
    //调用同步 send 方法发送数据,将返回结dao果保存至PingReply实例
    PingReply reply = pingSender.Send(ipStr, timeout, buffer, options);
    int delayTime = 0;
    if (reply.Status == IPStatus.Success)
    {
    delayTime = (int)reply.RoundtripTime;
    }
    else
    delayTime = -1;
    return delayTime;
    }

    相关文章

      网友评论

          本文标题:PING 检测延迟

          本文链接:https://www.haomeiwen.com/subject/xqbdjktx.html