Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
default-gateway
Advanced tools
Package description
The default-gateway npm package provides a simple and efficient way to find the default gateway of the local machine's network interfaces. It supports multiple operating systems, including Windows, macOS, and Linux, making it a versatile tool for network-related programming tasks. This package can be particularly useful for applications that need to interact with the network layer of the operating system, such as determining the best route for network traffic or configuring network settings programmatically.
Finding the default gateway for IPv4
This feature allows you to asynchronously find the default IPv4 gateway of the local machine. The result is an object containing the gateway's IP address and the associated network interface.
const defaultGateway = require('default-gateway');
defaultGateway.v4().then(result => console.log(result));
Finding the default gateway for IPv6
Similar to the IPv4 feature, this allows for the asynchronous discovery of the default IPv6 gateway. The result includes the IPv6 gateway address and the network interface it is associated with.
const defaultGateway = require('default-gateway');
defaultGateway.v6().then(result => console.log(result));
The 'ip' package provides utilities for handling IP addresses, including the ability to parse and format them. While it doesn't offer direct functionality to find the default gateway, it complements 'default-gateway' by providing tools to work with the IP addresses that 'default-gateway' might return.
The 'network' package offers a broader range of network-related functionalities, including getting the user's IP address, gateway, and active network interfaces. It serves a similar purpose to 'default-gateway' but with additional features that might be useful for more comprehensive network programming tasks.
While not a third-party package but a core Node.js module, 'os' provides basic operating system-related utility functions. It includes methods to retrieve network interface details. However, it does not directly provide the default gateway information, making 'default-gateway' a necessary complement for specific gateway-related tasks.
Readme
Obtains the machine's default gateway through exec
calls to OS routing ints.
ip
command must be available (usually provided by the iproute2
package).netstat
command must be available.wmic
must be available.db2util
command must be available (provided by the db2util
package).import {gateway4async, gateway4sync, gateway6async, gateway6sync} from "default-gateway";
const {gateway, version, int} = await gateway4async();
// gateway = '1.2.3.4', version = 4, int = 'en1'
const {gateway, version, int} = await gateway6async();
// gateway = '2001:db8::1', version = 6,int = 'en2'
const {gateway, version, int} = gateway4sync();
// gateway = '1.2.3.4', version = 4, int = 'en1'
const {gateway, version, int} = gateway6sync();
// gateway = '2001:db8::1', version = 6, int = 'en2'
Returns: result
Object
gateway
String: The IP address of the default gateway.version
Number: The IP address version of gateway
.int
String: 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.
© silverwind, distributed under BSD licence
FAQs
Get the default network gateway, cross-platform.
The npm package default-gateway receives a total of 10,996,531 weekly downloads. As such, default-gateway popularity was classified as popular.
We found that default-gateway demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.