Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用节点mtr?_Node.js_Traceroute - Fatal编程技术网

Node.js 如何使用节点mtr?

Node.js 如何使用节点mtr?,node.js,traceroute,Node.js,Traceroute,我想用mtr测量nodejs上的一些网络主机,我找到了包装器。在node-mtr-github中,我尝试使用npm-install-mtr进行安装,但之后我不知道如何使用node-mtr。我已经搜索了如何使用或示例代码,但没有找到 任何人都可以告诉我如何使用或给我一个示例代码?示例代码: var mtr = require('mtr').Mtr; var mtrTest = new mtr('127.0.0.1'); mtrTest.traceroute(); mtrTest.on('hop

我想用mtr测量nodejs上的一些网络主机,我找到了包装器。在node-mtr-github中,我尝试使用npm-install-mtr进行安装,但之后我不知道如何使用node-mtr。我已经搜索了如何使用或示例代码,但没有找到

任何人都可以告诉我如何使用或给我一个示例代码?

示例代码:

var mtr = require('mtr').Mtr;
var mtrTest = new mtr('127.0.0.1');

mtrTest.traceroute();

mtrTest.on('hop', function(hop) {
    console.log(hop);
});

mtrTest.on('error', function(err) {
    console.error(err);
});
结果

{ ip: '127.0.0.1',
  hostname: null,
  number: 1,
  rtts:
   [ 0.087, 0.042, 0.098, 0.092, 0.035, 0.07, 0.068, 0.044, 0.07, 0.093 ] }