Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

icmp

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icmp - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

43

index.js
const raw = require('raw-socket');
const net = require('net');
const dns = require('dns');
class ICMP {
constructor(ipv4, host) {
this.host = host || ipv4;
this.ip = ipv4;
constructor(host) {
this.host = host;
if (net.isIP(host)) {
this.ip = host;
} else {
dns.resolveAny(host, (err, addr) => {
if (err) console.log(err);
this.ip = addr[0];
});
}
this.socket = raw.createSocket({

@@ -18,3 +28,11 @@ protocol: raw.Protocol.ICMP

send(data = "") {
close() {
this.socket.close();
if(this._timeout) {
clearTimeout(this._timeout);
}
}
send(data = "", timeout = 5000) {
return new Promise((resolve, reject) => {

@@ -50,2 +68,7 @@ const datastr = String(data);

this._timeout = setTimeout(() => {
resolve();
this.close();
}, timeout);
this.start = process.hrtime()[1];

@@ -62,3 +85,3 @@ });

this.socket.close();
this.close();

@@ -76,3 +99,3 @@ this.parse(type, code);

static send(host, data = "") {
static send(host, data = "", timeout = 5000) {
const obj = new this(host);

@@ -86,8 +109,8 @@

ping() {
return this.send();
ping(timeout = 5000) {
return this.send('', timeout);
}
static ping(host) {
return this.send(host);
static ping(host, timeout = 5000) {
return this.send(host, '', timeout);
}

@@ -94,0 +117,0 @@

{
"name": "icmp",
"version": "1.1.1",
"version": "1.2.0",
"description": "Internet Control Message Protocol in Node",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,4 +5,3 @@ # Internet Control Message Protocol in Node

# How to install
Install with npm:
> `npm install --save icmp`
Install with npm: `npm install --save icmp`

@@ -46,9 +45,11 @@ # How to use

## Methods
### (static) ICMP.ping(host: string): Promise<ICMP>
Note: default `timeout` of each methods is `5000ms`.
### (static) ICMP.ping(host: string, timeout?: number): Promise<ICMP>
Send a ping to a specific host. Returns a Promise resolving an ICMP instance and rejecting an Error.
### ICMP.ping(): Promise<ICMP>
### ICMP.ping(timeout?: number): Promise<ICMP>
Send a ping to the defined ICMP instance's host. Returns a Promise, resolving nothing and rejecting an Error.
### (static) ICMP.send(host: string, data: string)
### (static) ICMP.send(host: string, data?: string)
Send data to a specific host through ICMP. Returns a Promise resolving an ICMP instance and rejecting an Error.

@@ -64,6 +65,9 @@

### ICMP.send(data: string)
### ICMP.send(data?: string, timeout?: number)
Send data to the defined ICMP instance's host. Returns a Promise resolving nothing and rejecting an Error.
### ICMP.close()
Close the raw socket stream. Can be used to stop a request.
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc