Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "Ping" from a Node.js app?

Tags:

node.js

I want to ping a server from my node.js app.

Is that doable?

Thanks

like image 262
donald Avatar asked Jan 19 '11 15:01

donald


People also ask

How do you ping An app?

In Windows, hit Windows+R. In the Run window, type “cmd” into the search box, and then hit Enter. At the prompt, type “ping” along with the URL or IP address you want to ping, and then hit Enter.

How do I ping an IP address in JavaScript?

open("GET", url, true); ping. send();


2 Answers

You could use exec to call the system ping command

var sys = require('sys') var exec = require('child_process').exec; function puts(error, stdout, stderr) { sys.puts(stdout) } exec("ping -c 3 localhost", puts); 
like image 191
Nikolaus Gradwohl Avatar answered Oct 08 '22 07:10

Nikolaus Gradwohl


node-net-ping is an awesome module that uses raw sockets.

And, if you are looking for only raw sockets, the same developer has a module for that too: node-raw-socket.

like image 45
umutm Avatar answered Oct 08 '22 08:10

umutm