danielzzz / node-ping Goto Github PK
View Code? Open in Web Editor NEWa poor man's ping library (using udp scanning) for node
License: MIT License
a poor man's ping library (using udp scanning) for node
License: MIT License
I got messages 'Response with unknown request ID from 10.193.165.1. Consider increasing timeouts (21946 ms old?).' But when I ping 10.193.165.1 response is fine , please advise
$ ping 10.193.165.1
PING 10.193.165.1 (10.193.165.1) 56(84) bytes of data.
64 bytes from 10.193.165.1: icmp_seq=1 ttl=62 time=80.0 ms
^C
--- 10.193.165.1 ping statistics ---
2 packets transmitted, 1 received, 50% packet loss, time 1052ms
rtt min/avg/max/mdev = 80.084/80.084/80.084/0.000 ms
there is a case in windows that fails
this._times.push(parseFloat(match[1], 10));
TypeError: Cannot read property '1' of null
domain: hotel-capitol-kuala-lumpur.com
the error is in win.js
some answers are different
[ 'bytes=32', 'tiempo<1m', 'TTL=128' ]
they do not contain ms
var timeKVP = __.find(kvps, function (kvp) {
return kvp.indexOf('ms') >= 0;
});
the solution is very easy. I hope you update it. a greeting
this is the code that I'm using:
ping.promise.probe("127.0.0.1",{min_reply: 3} ).then(function (res) { console.log(res); });
but its using the default value and doing just 1 call.
I 'm using windows machine
Currently the callback style only returns an alive boolean,
where the promise resolves with an object containing formally the host and alive, but now also includes the result string as of #23
Would you be open to making the result consistent between the two implementations? If we are changing the callback style result from a boolean to an object it would be a good time to consider an (err, result) callback signature as changing the result type is an API breaking change anyway.
I can write the implementation for this, but a major version increment will be needed.
When will 0.2.2 be pushed to npm? Right now it has 0.2.1 Just curious.
Hey, so I'm testing this code in a node.js package and it doesn't seem that the ping function is successfully hitting any endpoint.
` var hosts = ['192.168.1.1', 'google.com', '127.0.0.1:5000'];
hosts.forEach(function (host) {
ping.promise.probe(host)
.then(function (res) {
console.log(res);
});
});`
I'm not sure what the first host is. Google of course....is Google lol. and that last host and port is a local server in spinning up on python just for testing.
[0] { host: 'unknown', [0] alive: false, [0] output: '', [0] time: 'unknown', [0] min: 'unknown', [0] max: 'unknown', [0] avg: 'unknown', [0] stddev: 'unknown' } [0] { host: '192.168.1.1', [0] alive: false, [0] output: 'PING 192.168.1.1 (192.168.1.1): 56 data bytes\n\n--- 192.168.1.1 ping statistics ---\n1 packets transmitted, 0 packets received, 100.0% packet loss\n', [0] time: 'unknown', [0] min: 'unknown', [0] max: 'unknown', [0] avg: 'unknown', [0] stddev: 'unknown', [0] numeric_host: '192.168.1.1' } [0] { host: 'google.com', [0] alive: false, [0] output: 'PING google.com (172.217.12.238): 56 data bytes\n\n--- google.com ping statistics ---\n1 packets transmitted, 0 packets received, 100.0% packet loss\n', [0] time: 'unknown', [0] min: 'unknown', [0] max: 'unknown', [0] avg: 'unknown', [0] stddev: 'unknown', [0] numeric_host: '172.217.12.238' }
I'm unable to get a successful response, even with google or my local host that I know is running.
Is there a definition file for this module? I couldn't find one, and am having problems trying to create one of my own.
Thanks,
John
Can you add the loss percentage as and perimeter output?
Thanks
I am running ping with promise on macOS and it works fine, however when I pushed the code to production server which is
Linux 4.4.0-36-generic #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
I get this result
{
host: 'google.com',
alive: false,
output: 'PING google.com (46.162.192.44) 56(84) bytes of data.\n64 bytes from 46.162.192.44: icmp_seq=1 ttl=60 time=1.62 ms\n64 bytes from 46.162.192.44: icmp_seq=2 ttl=60 time=1.53 ms\n\n--- google.com ping statistics ---\n2 packets transmitted, 2 received, 0% packet loss, time 1001ms\nrtt min/avg/max/mdev = 1.531/1.577/1.623/0.046 ms\n',
time: 1.62
}
Why is the alive value false when the packet loss is 0%. I ended up manually checking the out put for the correct result.
There is a race condition in which sometimes the ls.stdout.on('data',...)
event is fired after the ls.on('exit', ...
event, resulting in outstring
being ''
(empty string).
Maybe I have to sanitize the user input to strip any protocol, but it would be great to support http://google.com
Allow for ping options to specify the type of ping to be done. For example, somethings like:
opts = {
ipv4: true,
ipv6: true
};
ping.sys.probe(host, function(isAlive) {
}, opts);
If something like this can already be done, please could you indicate the correct way in the documentation.
There seems to be an issue using arguments with spaces with the child_process.spawn method on linux. This manifests itself in an error when using this module. (following that all hosts are dead)
example: from builder/linux.js
if (config.timeout) {
ret.push(util.format('-w %d', config.timeout));
}
The space between the '-w' and the integer causes spawn to think that these are two different arguments one with '-w' and one with (for example) ' 2', this causes ping to believe that the integer part of the argument is SPACE TWO which is an invalid number.
This error is received: stderr: ping: invalid number ' 2'
Removing this space in the configuration arguments for Linux seems to correct the issue.
You have added a Windows specific check:
if (p.match(/^win/)) {
var lines = outstring.split('\n');
// this is my solution on Chinese Windows8 64bit
result = false;
for (var t = 0; t < lines.length; t++) {
if (lines[t].search(/TTL=[0-9]+/i) > 0) {
result = true;
break;
}
}
}
else {
result = (code === 0) ? true : false;
}
If this check for windows is removed all together, it works fine. code returns 1 on failure in my Windows 7 machine. Following code is enough for Windows too:
ls.on('exit', function (code) {
var result;
result = (code === 0) ? true : false;
deferred.resolve({
host: addr,
alive: result,
output: outstring
});
});
how can i get the response-time?
i just want to get the RT of some urls
Hi, I'm trying to use "node-ping" on my project but there seems to be a dependency with a "footprint" module:
Error: Cannot find module 'footprint'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/dave/gps/node_modules/node-ping/context.js:3:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Can you include this module in the dependencies section of package.json?
Hi,
I get an error when I ping a alive computer. I'm using a French version of W10
Here is my code used using Windows 10 :
var ping = require ("ping");
ping.sys.probe('8.8.8.8', function(isAlive){
console.log(isAlive)
});
.\ping\lib\parser\win.js:56
this._times.push(parseFloat(match[1], 10));
^
TypeError: Cannot read property '1' of null
at WinParser._processBody (.\ping\lib\parser\win.js:56:42)
at WinParser.parser.eat (.\ping\lib\parser\base.js:125:14)
at .\underscore\underscore.js:73:21
at Function._.each._.forEach (.\underscore\underscore.js:153:9)
at ChildProcess.<anonymous> (.\ping\lib\ping-promise.js:76:12)
at ChildProcess.g (events.js:291:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Socket.<anonymous> (internal/child_process.js:342:11)
After investigation, I found that french version are not supported (I think).
I replace this :
if (kvps.length >= 3) {
// XXX: Assume time will alaways get keyword ms for all language
var timeKVP = __.find(kvps, function (kvp) {
return kvp.indexOf('ms') >= 0;
});
var regExp = /([0-9\.]+)/;
var match = regExp.exec(timeKVP);
this._times.push(parseFloat(match[1], 10));
}
by :
if (kvps.length >= 3) {
// XXX: Assume time will alaways get keyword ms for all language
var timeKVP = __.find(kvps, function (kvp) {
return kvp.indexOf('temps') >= 0;
});
var regExp = /([0-9\.]+)/;
var match = regExp.exec(timeKVP);
this._times.push(parseFloat(match[1], 10));
}
And it works fine. Maybe multi-language is not supported yet. I put it here anyway in case some ppl want to implement a solution.
Hi there, thank you for great package.
It will be great to add in README that 'timeout' parameter is in 'seconds', not 'milliseconds'. Just small suggestion, feel free to close this issue. Thanks!
Hello, I am looking for help in solving this problem. I want to return the result of this function which will be used by some other function.
`pingTest(){
let msg='initialized';
ping.promise.probe('www.google.com',{
extra:['-o']}).then(function(res){
msg=res;
});
console.log(msg);
return msg;
}`
My pingTest function return 'initialized'. How can I get the 'res' value into 'msg' and return that from 'pingTest' function?
I have gone through Async function concepts in js, still unable to resolve this.
Thanks,
I'm trying to use this code to simply output the average ping. The output of console.log(res);
gives an example output of:
{ host: '192.168.1.102',
alive: true,
output: '\r\nPinging 192.168.1.102 with 32 bytes of data:\r\nReply from 192.168.1.102: bytes=32 time<1ms TTL=64\r\n\r\nPing statistics for 192.168.1.102:\r\n Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n Minimum = 0ms, Maximum = 0ms, Average = 0ms\r\n',
time: undefined }
I just want to get the number of average ping time, and have tried console.log(res.avg);
however this just returns undefined
- weirdly enough, doing console.log(res.alive);
returns true, so this method of using res.foo
should work. I'm on Windows but need to be able to run this on Linux too.
Am I stuck with parsing the full console.log(res);
output?
I noticed that the output is given as raw text, it will be really helpful to parse it and return a JSON object with ttl, time...
Hi guys,
I'd like to contribute with an issue and a feature. It seems I haven't got push accesss to this repository. Can someone help me?
Thanks, woicha
As #67 introduces IPV6, we need your helps on gathering fixtures for running ping6
. Otherwise, ipv6 may not be work in your platform.
The more fixtures we have the more faith we have to make ipv6 on your platform :)
For MacOS, please paste out output from following command
ping6 -c 2 IPV6_DOMAIN
For Window, please paste out output from following command
ping -6 IPV6_DOMAIN
For Linux, ????
Hi!
Tried ping
like this:
timeout = 15
host = '8.8.8.8'
#-----------------------------
ping = require 'ping'
ping.sys.promise_probe host,
timeout: timeout
.then (res) ->
console.log(res)
The res
only reports the hostname and a boolean status:
{
host: '8.8.8.8',
alive: true
}
I want to know the round trip time in milliseconds. How do i do that?
The promise version doesn't seem to work. I tried it under MacOSX. The promise function is not executed.
'use strict';
var ping = require('ping');
console.log('here');
var host = 'heise.de';
ping.promise.probe(host).then(function (res) {
console.log(res);
console.log('done');
});
I couldn't find any example for a continuos ping, so i tried to make one myself with Node and Angular.
Node
'use strict'
var ping = require('ping');
var http = require('http');
module.exports = function (router) {
var hosts = [
'8.8.8.8',
'192.168.1.1',
'192.168.0.1',
'192.168.0.2',
'192.168.0.3',
'192.168.0.4',
'192.168.0.5',
'192.168.0.6',
'192.168.0.7',
'192.168.0.8',
];
var messages = [];
function scan() {
hosts.forEach(function (host) {
ping.promise.probe(host, {
timeout: 2,
//min_reply: 2,
// extra: ["-i 2"],
}).then(function (res) {
//console.log(`${res.host} ${res.alive} ${res.time}`);
messages.push({ ip: res.host, status: res.alive, time: res.time })
});
});
console.log('before',messages.length)
messages = [];
setTimeout(scan, 5000);
}
scan();
router.post('/getData', function (req, res) {
console.log('after',messages.length)
res.send(messages)
})
return router //return whatever the route is
}
Angular
.controller('mainCtrl', function ($http, $timeout) {
var main = this;
function scan() {
$http.post('api/getData', { test: 'testing data' })
.then(function (response) {
console.log(response.data.length)
main.pingData = response.data
})
setTimeout(scan, 5000);
}
scan();
})
This gives like 80% of the time the correct output, and it's not good enough.
Any ideas on how could i improve it?
in osx and linux the footer is sth like round-trip min/avg/max/stddev = 4.504/5.157/6.147/0.508 ms
, but it seems parse the 2nd number as result.max
and 3rd number as result.avg
see https://github.com/danielzzz/node-ping/blob/master/lib/parser/mac.js#L68
Hello!
In addition to 'host' and 'result', would it be possible for the library to return the output of the 'ping' command as well? Some user might be interested in the 'ping' command statistics and can read from the outstring, if returned by the library.
deferred.resolve({
host: addr,
alive: result,
output: outstring // --> this is missing
Thanks!
Regards
mabukar
Hi,
I have a bug about pinging in Windows; I saw the source code in github but it is already fixed (line 86 in "ping-promise.js"). Could you please publish a new release version in NPM so I could use the newest module with the bug fixed? Thanks
As #72 illustrate, there are different locale setting on units ms
Window setting. We need to refactor the Window's parser to better support the locale variation. Maybe scanning with a list of possible units?
[en,fr,ja,zh] -> [ms]
[ru] -> [мс, мсек]
[es] ->[m, ms]
I didn't find the function of ping with port in document, I want to know this can work?
Hi Daniel
As a french guy, here the 'ping' answer I received:
"R�ponse de 10.50.0.156�: octets=32 temps=158 ms TTL=120"
Because of the space between the '158' value and 'ms' an error happens.
kvps.length >= 3
but match
is null in win.js (_processBody function), so when match[1]
is called an error is thrown...
adding the following code just after the var tokens = line.split(' ')
fixed that issue
const msToken = tokens.indexOf('ms')
if (msToken > 0) {
tokens[msToken - 1] += 'ms'
tokens.splice(msToken, 1)
}
To run on windows, you need to change the command call to:
var ls = spawn('C:/windows/system32/ping.exe', ['-n', '1', '-w', '5000', addr]);
Ideally this code should be modified to detect OS and then make the appropriate call.
any chance of making the README example actually work with the underlying lib ? Thanks
Hi.. Thanks for at super nice and simple module.
Minor thing really.. On the documentation on npmjs.com there a minor typo..
Under Tradition calls with configuration
. The extra:
line is like below.
...
extra: ["-i 2"],
...
But should really be like this.
...
extra: ['-i', '2'],
...
Just like the documentation here on Github. Or else it wont work.
Thanks
hi, if possible would you please update the contributors list and make sure the package is ready for release? I would upload it then to npm.
0.2.0 sounds fine?
thanks again for all your help!
dan
What is the size of the packet being transferred and can i change it?
Hi guys,
many thanks for your very good and easy to use module, especially since you solved the parsing issues to support many international versions of Windows. I'm using a german Windows 10 Enter Enterprise edition and everything seems to work perfect with the actual version on github.
My only problem is, that on npmjs.com an older version seems to published. Could you publish the newest version there so that I'm able to use the "npm install ..." command in our project? Or is there another way to install the actual version under our project's "node_modules" subdirectory? (Sorry, I'm a beginner.)
By the way: the entry "version" in the newest package.json is "0.2.2"; the same shows in the package.json I received by running the "npm install ..." command.
Thanks.
Hi Team,
I got following error when run npm install
npm WARN package.json [email protected] No README data
/
[email protected] install /var/www/html/netping/node_modules/raw-socket
node-gyp rebuild
make: Entering directory '/var/www/html/netping/node_modules/raw-socket/build'
CXX(target) Release/obj.target/raw/src/raw.o
../src/raw.cc: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE raw::SocketWrap::Send(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/raw.cc:662:3: error: ‘Utf8String’ is not a member of ‘v8::String’
String::Utf8String address (args[3]);
^
../src/raw.cc:663:44: error: ‘address’ was not declared in this scope
struct sockaddr_in6 addr = uv_ip6_addr (_address, 0);
^
../src/raw.cc:673:3: error: ‘Utf8String’ is not a member of ‘v8::String’
String::Utf8String address (info[3]);
^
../src/raw.cc:674:43: error: ‘address’ was not declared in this scope
struct sockaddr_in addr = uv_ip4_addr (_address, 0);
My english windows returns following if destination not reachable:
'''
C:>ping 192.168.1.72
Pinging 192.168.1.72 with 32 bytes of data:
Reply from 192.168.1.69: Destination host unreachable.
Reply from 192.168.1.69: Destination host unreachable.
Reply from 192.168.1.69: Destination host unreachable.
Reply from 192.168.1.69: Destination host unreachable.
Ping statistics for 192.168.1.72:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
'''
And
lines[t].indexOf ('(0%')>0
returns true on the "Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),"
Hi,
I have created a npm package with your ping package but seems that is not working on android mobile phone, I am using an S8 with termux.
npm install is-server-alive
Hi,
i'm using the library on an embedded Linux OS where an stderror occured.
When i installed the module via npm install ping i found out that the src-code is different compared with the git src-code.
npm installed the version 0.1.10. You can not install the 0.2.0 Version with npm install ping @0.2.0.
PM2 starts the Ping module and always plays the window
timeout is in miliseconds?
i may have gotten old version from npm 0.1.10.
suggested change:
args = ['-n', '1', '-w', config.timeout];
When I install this library it does not seem to install the 'child_process' library as a dependency and therefore errors as above.
I want to stop next ping when I get an alive IP.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.