danielzzz / node-ping

a poor man's ping library (using udp scanning) for node
MIT License
336 stars 105 forks source link

WSL bash always returns host down #111

Closed roughnecks closed 4 years ago

roughnecks commented 4 years ago

Hello, here's my script:

var ping = require('ping');
const fs = require('fs');

var hosts = ['192.168.1.253'];
hosts.forEach(function(host){
    ping.sys.probe(host, function(isAlive){
        if (isAlive) {
            return;
        } else {
            d = new Date().toLocaleString();
            fs.appendFile("/mnt/c/Users/roughnecks/Desktop/ping.txt", "Access Point is Down! - " + d + "\n" , function(err) {
                if(err) {
                    return;
                }
                //console.log("The file was saved!");
            });
        }
    });
});

This used to work but for some reason on my new WSL Debian install it always reports "host down", Can you help?

roughnecks@CUSPIDE:~$ node --version v12.16.1

roughnecks@CUSPIDE:~$ cat /etc/debian_version 10.3

Thanks

mondwan commented 4 years ago

I suggest you to rewrite this program with promise based. Then, try to take a look the error from the promised, and see what's happening

Simone notifications@github.com 於 2020年2月27日週四 上午12:06寫道:

Hello, here's my script:

var ping = require('ping'); const fs = require('fs');

var hosts = ['192.168.1.253']; hosts.forEach(function(host){ ping.sys.probe(host, function(isAlive){ if (isAlive) { return; } else { d = new Date().toLocaleString(); fs.appendFile("/mnt/c/Users/roughnecks/Desktop/ping.txt", "Access Point is Down! - " + d + "\n" , function(err) { if(err) { return; } //console.log("The file was saved!"); }); } }); });

This used to work but for some reason on my new WSL Debian install it always reports "host down", Can you help?

roughnecks@CUSPIDE:~$ node --version v12.16.1

roughnecks@CUSPIDE:~$ cat /etc/debian_version 10.3

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/111?email_source=notifications&email_token=AA5YBI26VV2H3TIWPZG2M2LRE2HOZA5CNFSM4K4I3XGKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IQQJJOQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI4MLNWAC23LH7SVJC3RE2HOZANCNFSM4K4I3XGA .

roughnecks commented 4 years ago

New script, just copy-pasted from README:

var ping = require('ping');

var hosts = ['192.168.1.253'];

hosts.forEach(function (host) {
    ping.promise.probe(host)
        .then(function (res) {
            console.log(res);
        });
});

roughnecks@CUSPIDE:~/scripts$ node pingpromise.js { host: 'unknown', alive: false, output: '', time: 'unknown', min: 'unknown', max: 'unknown', avg: 'unknown', stddev: 'unknown' }

mondwan commented 4 years ago

Since you have installed a new system, did you install ping in your system?

Simone notifications@github.com 於 2020年2月27日週四 上午12:24寫道:

New script, just copy-pasted from README:

var ping = require('ping');

var hosts = ['192.168.1.253'];

hosts.forEach(function (host) { ping.promise.probe(host) .then(function (res) { console.log(res); }); });

roughnecks@CUSPIDE:~/scripts$ node pingpromise.js { host: 'unknown', alive: false, output: '', time: 'unknown', min: 'unknown', max: 'unknown', avg: 'unknown', stddev: 'unknown' }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/111?email_source=notifications&email_token=AA5YBIYK2ZV4NJF6NPPIFGTRE2JSRA5CNFSM4K4I3XGKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENA4ZHI#issuecomment-591514781, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI6ZGBRVTYPPRTZYZ2LRE2JSRANCNFSM4K4I3XGA .

roughnecks commented 4 years ago

I have installed with:

npm install ping

Now I also tried with:

npm install node-ping

But it's still not working

mondwan commented 4 years ago

No. I mean the ping in your system. Can you run ping in your debian terminal?

Simone notifications@github.com 於 2020年2月27日週四 上午12:31寫道:

I have installed with:

npm install ping

Now I also tried with:

npm install node-ping

But it's still not working

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/111?email_source=notifications&email_token=AA5YBI6PIOWLRGIRUWGCZNLRE2KNJA5CNFSM4K4I3XGKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENA5VSI#issuecomment-591518409, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI336MWRQS2YCAFKWJ3RE2KNJANCNFSM4K4I3XGA .

roughnecks commented 4 years ago

Yes, it's installed but it doesn't actually work.

"ping: socket: Operation not permitted"

I wonder how did I manage to have it working in my old setup, which was pretty much the same.

roughnecks commented 4 years ago

Hey, I fixed it by running this:

sudo chmod u+s which ping

Which was referenced here: https://github.com/microsoft/WSL/issues/18#issuecomment-463743967