Socket
Socket
Sign inDemoInstall

default-gateway

Package Overview
Dependencies
5
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.4 to 0.8.5

2

package.json
{
"name": "default-gateway",
"version": "0.8.4",
"version": "0.8.5",
"description": "A Node.js module to get default gateway and default interface.",

@@ -5,0 +5,0 @@ "author": "silverwind <me@silverwind.io>",

@@ -5,20 +5,8 @@ # default-gateway

This module depends on following commands by using [chid_process](https://nodejs.org/api/child_process.html):
This module is based on [previous work](https://github.com/mh61503891/node-default-network) from @mh61503891.
- win32
- `wmic path Win32_NetworkAdapterConfiguration get *`
- `wmic path Win32_NetworkAdapter get *`
- darwin
- `netstat -rn -f inet`
- `netstat -rn -f inet6`
- linux
- `netstat -rn -A inet`
- `netstat -rn -A inet6`
This module is based on [previous work from mh61503891](https://github.com/mh61503891/node-default-network).
## Installation
```bash
npm install default-gateway
npm install --save default-gateway
```

@@ -32,8 +20,4 @@

#### Example 1
#### Example 1 - Get default gateway and default interface
How to get default gateway and default interface.
An example code: `example1.js`
```js

@@ -43,65 +27,66 @@ var defaultGateway = require('default-gateway');

console.log(data);
// { en4:
// [ { family: 'IPv4', address: '192.168.1.1' },
// { family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en4' } ],
// en0:
// [ { family: 'IPv4', address: '192.168.1.1' },
// { family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en0' } ],
// en8:
// [ { family: 'IPv4', address: '192.168.1.1' },
// { family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en8' } ]
// }
});
```
#### Example 2 - Get default interface from `os.networkInterfaces()`.
An example output:
```js
{ en4:
[ { family: 'IPv4', address: '192.168.1.1' },
{ family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en4' } ],
en0:
[ { family: 'IPv4', address: '192.168.1.1' },
{ family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en0' } ],
en8:
[ { family: 'IPv4', address: '192.168.1.1' },
{ family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en8' } ] }
```
#### Example 2
How to get default interface from `os.networkInterfaces()`.
An example code: `example2.js`
```js
var os = require('os');
var defaultGateway = require('default-gateway');
defaultGateway(function(error, data) {
names = Object.keys(data);
// names[0] is 'en4'
names = Object.keys(data); // names[0] is 'en4'
console.log(os.networkInterfaces()[names[0]]);
// [
// { address: 'fe80::6a5b:35ff:fe96:cc05',
// netmask: 'ffff:ffff:ffff:ffff::',
// family: 'IPv6',
// mac: '00:00:00:00:00:00',
// scopeid: 14,
// internal: false },
// { address: '2001:a0ae:7c22:0:6a5b:35ff:fe96:cc05',
// netmask: 'ffff:ffff:ffff:ffff::',
// family: 'IPv6',
// mac: '00:00:00:00:00:00',
// scopeid: 0,
// internal: false },
// { address: '2001:a0ae:7c22:0:a8d1:fef3:2917:cd87',
// netmask: 'ffff:ffff:ffff:ffff::',
// family: 'IPv6',
// mac: '00:00:00:00:00:00',
// scopeid: 0,
// internal: false },
// { address: '192.168.1.10',
// netmask: '255.255.255.0',
// family: 'IPv4',
// mac: '00:00:00:00:00:00',
// internal: false }
// ]
});
```
An example output:
## How it works
```js
[ { address: 'fe80::6a5b:35ff:fe96:cc05',
netmask: 'ffff:ffff:ffff:ffff::',
family: 'IPv6',
mac: '00:00:00:00:00:00',
scopeid: 14,
internal: false },
{ address: '2001:a0ae:7c22:0:6a5b:35ff:fe96:cc05',
netmask: 'ffff:ffff:ffff:ffff::',
family: 'IPv6',
mac: '00:00:00:00:00:00',
scopeid: 0,
internal: false },
{ address: '2001:a0ae:7c22:0:a8d1:fef3:2917:cd87',
netmask: 'ffff:ffff:ffff:ffff::',
family: 'IPv6',
mac: '00:00:00:00:00:00',
scopeid: 0,
internal: false },
{ address: '192.168.1.10',
netmask: '255.255.255.0',
family: 'IPv4',
mac: '00:00:00:00:00:00',
internal: false } ]
```
This module depends on following commands by using [child_process](https://nodejs.org/api/child_process.html):
- win32
- `wmic path Win32_NetworkAdapterConfiguration get *`
- `wmic path Win32_NetworkAdapter get *`
- darwin
- `netstat -rn -f inet`
- `netstat -rn -f inet6`
- linux
- `netstat -rn -A inet`
- `netstat -rn -A inet6`
## License
The MIT License
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc