# @pcelvng/net

> simple network diagnostic tool chest.

Latest version **0.12.1** (published 2018-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pcelvng/net
pnpm add @pcelvng/net
yarn add @pcelvng/net
bun add @pcelvng/net
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.1 |
| Published | 2018-10-26 |
| First published | 2018-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 44.8 KB |
| Known vulnerabilities | 0 (+4 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | rlball |
| Maintainers | rlball |
| Keywords | ping, net-ping, net, netstats, gateway, network utils, pings, ip geo location, geo ip, public ip, mac address, network map, arp, icmp, network, dns, reverse-dns, speed test, traceroute, download speed, upload speed |

## Links

- npm: https://www.npmjs.com/package/@pcelvng/net
- Repository: https://github.com/pcelvng/netjs
- Issues: https://github.com/pcelvng/netjs/issues
- npm.io page: https://npm.io/package/@pcelvng/net

## Dependencies (11)

- [ip](https://npm.io/package/ip.md) ^1.1.5
- [address](https://npm.io/package/address.md) ^1.0.3
- [network](https://npm.io/package/network.md) ^0.4.1
- [request](https://npm.io/package/request.md) ^2.88.0
- [node-arp](https://npm.io/package/node-arp.md) ^1.0.6
- [tcp-ping](https://npm.io/package/tcp-ping.md) ^0.1.1
- [iplocation](https://npm.io/package/iplocation.md) ^5.0.1
- [external-ip](https://npm.io/package/external-ip.md) ^2.0.3
- [local-devices](https://npm.io/package/local-devices.md) ^1.1.1
- [speedtest-net](https://npm.io/package/speedtest-net.md) ^1.4.3
- [nodejs-traceroute](https://npm.io/package/nodejs-traceroute.md) ^1.1.1

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.12.1 (latest) — 2018-10-26
- 0.12.0 — 2018-10-26
- 0.11.0 — 2018-10-26
- 0.10.3 — 2018-10-25
- 0.10.2 — 2018-10-25
- 0.10.1 — 2018-10-24
- 0.10.0 — 2018-10-24
- 0.9.2 — 2018-10-01
- 0.9.1 — 2018-10-01
- 0.9.0 — 2018-10-01
- 0.8.1 — 2018-09-24
- 0.8.0 — 2018-09-24
- 0.7.0 — 2018-09-20
- 0.6.0 — 2018-09-20
- 0.5.0 — 2018-09-10
- … 6 more at https://npm.io/package/@pcelvng/net/versions

## README

# @pcelvng/net

@pcelvng/net is a node.js package containing a collection
of network utilities for gathering information about a 
client network environment.

## Installation

```bash
$ npm install @pcelvng/net --save
```

## Node Webkit Installation

Since the 'net-socket' dependency relies on a c module, Node Webkit requires that to be
into the runtime environment. Instructions on doing this can be found below:

[NWJS Use Native Node Modules](http://docs.nwjs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/#for-non-lts-releases)

## Usage

All usage examples are located in the examples directory. Examples 
are reproduced below for convenience.

### corelocalnetwork example

```js
const net = require("../net.js");
const util = require('util');

// easily obtain the client host - the host where the test
// is being run.
net.clientHost((cHst) => {
    console.log("client host object: ");
    console.log(util.inspect(cHst, false, null, true));
    console.log("");
});

// get the client host along with general information about the
// client.
net.client((clnt) => {
    console.log("client host object and general client info: ");
    console.log(util.inspect(clnt, false, null, true));
    console.log("");
});

// get the network nats to discover if you have more than
// one nat.
// note: if the nat also has the 'gateway' role then
// that is the nat that is the gateway to the internet.
net.nats((nts) => {
    console.log("local network nats: ");
    console.log(util.inspect(nts, false, null, true));
    console.log("");
});

// get the internet host which is the 'public' side
// of the local nat. It's the host that has your local network
// public ip address.
// It's the only host relative to the client local network that
// is public.
// Other public hosts are designated with the 'remote' role. Meaning
// they are remote to the client's local network.
net.publicHost((pHst) => {
    console.log("public host: ");
    console.log(util.inspect(pHst, false, null, true));
    console.log("");
});

// conveniently get the entire 'core local network'
// in a single call.
net.coreLocalNetwork((hsts) => {
    console.log(util.inspect(hsts, false, null, true));
});
```

### host example

```js
const net = require("../net.js");
const util = require('util');

// hosts are represented by host objects.
// generate a host object yourself like this:
let myHost = new net.Host();

// you can set your host information and then augment it will various
// host functions.
myHost.name = 'www.google.com';

// with just a host do an ip lookup
// note: the 'myHost' in the callback is a reference
// to the same object.
net.hostIpLookup(myHost, (myHost) => {
    console.log("myHost with ip address: ");
    console.log(util.inspect(myHost, false, null, true));

    // with the ip address in, hand do an ip geo lookup
    net.hostGeoLookup(myHost, (myHost) => {
       console.log("myHost with geo info: ");
       console.log(util.inspect(myHost, false, null, true));
    });
});

// if you have an ip and want to find the host name
// do a host name lookup. Can also work with private
// ips if the local network has dns servers and
// the private host has a dns host name.
let h = new net.Host();
h.ip = "8.22.12.170"; // probably need to update the example with an ip that has a host name.
h.is_public = true;

net.hostNameLookup(h, (hst) => {
    console.log("host name lookup:");
    console.log(util.inspect(hst, false, null, true));
});

// if you have a host interface mac address then perform
// a vendor string lookup (note: rate limited to 1 per second)
let macHost = new net.Host();
macHost.mac = '8c:85:90:cd:ba:0e';

// note: the 'macHost' in the callback is a reference
// to the same object.
net.hostVendorLookup(macHost, (macHost) => {
   console.log("mac address vendor lookup: ");
   console.log(util.inspect(macHost, false, null, true));
});

```

### localnetwork example

```js
const net = require("../net.js");
const util = require('util');

// generate all localnetwork objects including
// and especially the core local network hosts.
net.localNetwork((hsts) => {
    for (let i = 0; i < hsts.length; i++) {
        console.log(util.inspect(hsts[i], false, null, true));
    }
});
```

### ping example

```js
const net = require("../net.js");
const util = require('util');

// do a bunch of pings
let cfg = net.newPingsCfg();
cfg.target = "www.google.com";
cfg.num_pings = 10;
net.pings(cfg, (result) => {
    console.log('do a bunch of pings and get stats');
    console.log(util.inspect(result, false, null, true));
    console.log('');
});

net.ping("www.google.com", (result) => {
    console.log('do a single ping');
    console.log(util.inspect(result, false, null, true));
    console.log('');
});

// url accessibility/liveness check
net.pingUrl("www.google.com/", (pErr, url) => {
    console.log("err since the url is not complete - poorly formed");
    if (pErr) {
        console.log(util.inspect(pErr.toString(), false, null, true));
    }
    console.log(util.inspect(url, false, null, true));
    console.log('');
});

// urls accessibility/liveness check
// an unreachable url wil simply return an empty string value
// in the returned 'urls' array. The order matches the original
// input urls order so the user can know which urls are unreachable.
net.pingUrls(["https://www.google.com/", "https://www.bad.com:8080"], (pErr, urls) => {
    console.log('check accessibility of a series of urls');
    if (pErr) {
        console.log(util.inspect(pErr.toString(), false, null, true));
    }
    console.log(util.inspect(urls, false, null, true));
    console.log('');
});

// how a bad url comes back
net.pingUrls(["https://www.google.com/", "www.bad.com"], (pErr, urls) => {
    console.log('poorly formed url will come back as empty when presented with a group of urls');
    // improperly formed url will result in err.
    if (pErr) {
        console.log(util.inspect(pErr.toString(), false, null, true));
    }
    console.log(util.inspect(urls, false, null, true));
    console.log('');
});
```

### speedtest example

```js
const net = require("../net.js");
const util = require('util');

// speed test options
let stCfg = {
    progressCb: progress => {
        console.log("progress... " + util.inspect(progress, false, null, true));
    },
};

// speed test is, for now, a simple wrapper around the awesome
// speedtest-net library. In the future it is possible there will be support
// for other speed test libraries as well as adding more options
// and normalizing the results to be independent of the underlying
// test driver.
net.speed(stCfg).then(
    stResult => {
        console.log(util.inspect(stResult, false, null, true));
    }
).catch(
    err => {
        console.log("err speedTest: " + err.toString());
    }
);
```

### traceroute example

```js
const net = require("../net.js");
const util = require('util');

// traceroute
let destination = new net.Host();
destination.name = "www.google.com";

net.traceroute(destination, (err, hops) => {
    console.log(util.inspect(hops, false, null, true));
});

```

## Special Thanks

Special thanks to all the great libraries that this project directly relies on. 

- ip
- iplocation
- local-devices
- net-ping
- network
- node-arp
- public-ip
- speedtest-net
- request

---
_Source: https://npm.io/package/@pcelvng/net · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
