Socket
Socket
Sign inDemoInstall

internal-ip

Package Overview
Dependencies
18
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0 to 6.0.0

40

index.js
'use strict';
const os = require('os');
const defaultGateway = require('default-gateway');
const ipaddr = require('ipaddr.js');
const {networkInterfaces} = require('os');
const {parse, parseCIDR} = require('ipaddr.js');
function findIp(gateway) {
const interfaces = os.networkInterfaces();
const gatewayIp = ipaddr.parse(gateway);
let ip;
const gatewayIp = parse(gateway);
// Look for the matching interface in all local interfaces
Object.keys(interfaces).some(name => {
return interfaces[name].some(addr => {
const prefix = ipaddr.parse(addr.netmask).prefixLengthFromSubnetMask();
const net = ipaddr.parseCIDR(`${addr.address}/${prefix}`);
// Look for the matching interface in all local interfaces.
for (const addresses of Object.values(networkInterfaces())) {
for (const address of addresses) {
const prefix = parse(address.netmask).prefixLengthFromSubnetMask();
const net = parseCIDR(`${address.address}/${prefix}`);
if (net[0] && net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) {
ip = net[0].toString();
return net[0].toString();
}
return Boolean(ip);
});
});
return ip;
}
}
}

@@ -30,5 +24,5 @@

try {
const result = await defaultGateway[family]();
return findIp(result.gateway);
} catch (_) {}
const {gateway} = await defaultGateway[family]();
return findIp(gateway);
} catch {}
}

@@ -38,5 +32,5 @@

try {
const result = defaultGateway[family].sync();
return findIp(result.gateway);
} catch (_) {}
const {gateway} = defaultGateway[family].sync();
return findIp(gateway);
} catch {}
}

@@ -43,0 +37,0 @@

{
"name": "internal-ip",
"version": "5.0.0",
"version": "6.0.0",
"description": "Get your internal IP address",
"license": "MIT",
"repository": "sindresorhus/internal-ip",
"funding": "https://github.com/sindresorhus/internal-ip?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -35,3 +36,3 @@ "scripts": {

"dependencies": {
"default-gateway": "^5.0.4",
"default-gateway": "^6.0.0",
"ipaddr.js": "^1.9.1"

@@ -41,5 +42,5 @@ },

"ava": "^2.4.0",
"tsd": "^0.9.0",
"tsd": "^0.11.0",
"xo": "^0.25.3"
}
}

@@ -5,3 +5,2 @@ # internal-ip [![Build Status](https://travis-ci.org/sindresorhus/internal-ip.svg?branch=master)](https://travis-ci.org/sindresorhus/internal-ip)

## Install

@@ -13,3 +12,2 @@

## Usage

@@ -39,3 +37,2 @@

## Related

@@ -47,3 +44,2 @@

---

@@ -50,0 +46,0 @@

Sorry, the diff of this file is not supported yet

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