Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including icmp with all npm packages installed. Try it out:

var icmp = require("icmp")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

icmp v1.4.0

Internet Control Message Protocol in Node

Internet Control Message Protocol in Node

Version Twitter: qtmsheep

Internet Control Message Protocol in Node

Install

npm install icmp

On Windows, the Windows Build Tools are required: npm install -g windows-build-tools

Usage

Properties

ICMP.host: string

The requested HOST (can be an IP)

ICMP.ip: string

The requested IP, when host parameter is given to the constructor, the DNS will be resolved to get this IP adress

ICMP.open: boolean

This property will be true or false, depending on the ping response

ICMP.type: string

ICMP response type, will be one from this array:

['REPLY', 'NA', 'NA', 'DESTINATION_UNREACHABLE', 'SOURCE_QUENCH', 'REDIRECT']

ICMP.code: string

ICMP response code, will be one from this array:

['NET', 'HOST', 'PROTOCOL', 'PORT', 'FRAGMENTATION', 'ROUTE_FAILED', 'NET_UNKNOWN', 'HOST_UNKNOWN', 'HOST_ISOLATED', 'NET_PROHIBITED', 'HOST_PROHIBITED', 'NET_UNREACHABLE', 'HOST_UNREACHABLE', 'COMM_PROHIBITED', 'HOST_PRECEDENCE', 'PRECEDENCE_CUTOFF', 'NETWORK', 'HOST', 'SERVICE_NETWORK', 'HOST_NETWORK']

Methods

Note: default timeout of each methods is 5000ms.

(static) ICMP.ping(host: string, timeout?: number): Promise

Send a ping to a specific host. Returns a Promise resolving an ICMP instance and rejecting an Error.

ICMP.ping(timeout?: number): Promise

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)

Send data to a specific host through ICMP. Returns a Promise resolving an ICMP instance and rejecting an Error.

icmp.send('10.43.65.9', "Hey, I'm sending a message!")
    .then(obj => {
        console.log(obj.open ? 'Done' : 'Failed')
    })
    .catch(err => console.log(err));

ICMP.send(data?: string, timeout?: number)

Send data to the defined ICMP instance's host. Returns a Promise resolving nothing and rejecting an Error.

(static) ICMP.listen(cb: (buffer, source) => void)

Listen to incomming ICMP requests.

ICMP.listen(cb: (buffer, source) => void)

Listen to incomming ICMP requests.

ICMP.close()

Close the raw socket stream. Can be used to stop a request.

Author

👤 Nathanael Demacon

Show your support

Give a ⭐️ if this project helped you!

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free