Package Exports
- default-gateway
Readme
default-gateway
Obtains the machine's default gateway through exec calls to OS routing ints.
- On Linux and Android, the
ipcommand must be available (usually provided by theiproute2package). - On Windows,
wmicmust be available. - On IBM i, the
db2utilcommand must be available (provided by thedb2utilpackage). - On Unix (and macOS), the
netstatcommand must be available.
Usage
import {gateway4async, gateway4sync, gateway6async, gateway6sync} from "default-gateway";
const {gateway, int} = await gateway4async();
// gateway = '1.2.3.4', int = 'en1'
const {gateway, int} = await gateway6async();
// gateway = '2001:db8::1', int = 'en2'
const {gateway, int} = gateway4sync();
// gateway = '1.2.3.4', int = 'en1'
const {gateway, int} = gateway6sync();
// gateway = '2001:db8::1', int = 'en2'API
gateway4async()
gateway6async()
gateway4sync()
gateway6sync()
Returns: result Object
gateway: The IP address of the default gateway.int: The name of the interface. On Windows, this is the network adapter name.
The gateway property will always be defined on success, while int can be null if it cannot be determined. All methods reject/throw on unexpected conditions.
License
© silverwind, distributed under BSD licence