代码之家  ›  专栏  ›  技术社区  ›  Prafulla Kumar Sahu umang naik

如何从监视主机C测量主机A和主机B之间的延迟

  •  1
  • Prafulla Kumar Sahu umang naik  · 技术社区  · 6 年前

    如何从监视/观察主机C测量主机A和主机B之间的延迟?

    我用过 Ping 模块在这里。

    var ping = require('ping');
    
    var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
    
    hosts.forEach(function (host) {
        ping.promise.probe(host)
            .then(function (res) {
                console.log(res);
            });
    });
    

    这个结果

    { host: 'google.com',
      alive: true,
      output: '\r\nPinging google.com [172.217.163.174] with 32 bytes of data:\r\nReply from 172.217.163.174: bytes=32 time=8ms TTL=55\r\n\r\nPing statistics for 172.217.163.174:\r\n    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 8ms, Maximum = 8ms, Average = 8ms\r\n',
      time: 8,
      min: '8.000',
      max: '8.000',
      avg: '8.000',
      stddev: '0.000',
      numeric_host: '172.217.163.174' }
    { host: 'yahoo.com',
      alive: true,
      output: '\r\nPinging yahoo.com [98.138.219.231] with 32 bytes of data:\r\nReply from 98.138.219.231: bytes=32 time=254ms TTL=44\r\n\r\nPing statistics for 98.138.219.231:\r\n    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 254ms, Maximum = 254ms, Average = 254ms\r\n',
      time: 254,
      min: '254.000',
      max: '254.000',
      avg: '254.000',
      stddev: '0.000',
      numeric_host: '98.138.219.231' }
    { host: '192.168.1.1',
      alive: false,
      output: '\r\nPinging 192.168.1.1 with 32 bytes of data:\r\nRequest timed out.\r\n\r\nPing statistics for 192.168.1.1:\r\n    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),\r\n',
      time: 'unknown',
      min: 'unknown',
      max: 'unknown',
      avg: 'unknown',
      stddev: 'unknown',
      numeric_host: '192.168.1.1' }
    

    但是我想传递两个IP地址并计算延迟,有什么方法可以这样做吗?

    如果有可能在任何其他编程语言,那么我也想知道。

    0 回复  |  直到 6 年前