5

Will be a support of raw sockets in node.js, e.g. to create ping packets?

John Bensin
  • 301
  • 2
  • 5
  • 20
sauletasmiestas
  • 428
  • 2
  • 6
  • 17

3 Answers3

7

A new module named node-raw-socket offers the perfect solution for real raw sockets using nodejs.

And, for creating ping (ICMP) packets, the same developer has a very nice working (using it) solution based on node-raw-sockets as well: node-net-ping.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
umutm
  • 2,832
  • 4
  • 22
  • 22
5

Node supports TCP, UDP, and unix sockets. Ping packets are ICMP packets, which node cannot create directly at this time. You could execute an external ping subprocess or consider writing a C extension. Most of node's low level OS APIs are thin javascript wrappers around the corresponding C API, so you could follow that existing well-established pattern and implement this as a small JS wrapper layer around the corresponding OS-level APIs.

http://nodejs.org/docs/latest/api/all.html#all_class_net_socket

There's a chance node/javascript are a poor choice for your project based on this requirement though.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • 1
    I think the solution should be to create an addon [addons](http://nodejs.org/docs/latest/api/all.html#all_addon_patterns) – sauletasmiestas Dec 10 '12 at 15:25
  • @Peter, There's no reason why Node supports TCP UDP, yet doesn't support IP. Support for IP must come sooner or later. – Pacerier Mar 03 '17 at 23:23
0

net-ping module may suit your need. to install it you can use the following command:

npm install net-ping

The documentation with examples is included here.

orezvani
  • 3,595
  • 8
  • 43
  • 57