Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

internal-ip

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

internal-ip - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

63

index.js
'use strict';
var os = require('os');
const os = require('os');
const defaultGateway = require('default-gateway');
// TODO: Remove dependency on ip module
// https://github.com/whitequark/ipaddr.js/issues/59
const ip = require('ip');
const ipaddr = require('ipaddr.js');
var type = {
v4: {
def: '127.0.0.1',
family: 'IPv4'
},
v6: {
def: '::1',
family: 'IPv6'
}
const defaults = {
v6: '::1',
v4: '127.0.0.1'
};
function internalIp(version) {
var options = type[version];
var ret = options.def;
var interfaces = os.networkInterfaces();
function internalIp(family) {
return defaultGateway[family]().then(result => {
const interfaces = os.networkInterfaces();
let ret;
Object.keys(interfaces).forEach(function (el) {
interfaces[el].forEach(function (el2) {
if (!el2.internal && el2.family === options.family) {
ret = el2.address;
}
});
});
// Remove IPv6 zone index and parse gateway address as a ipaddr.js object
// https://github.com/whitequark/ipaddr.js/issues/60
const gatewayIp = ipaddr.parse(result.gateway.replace(/%.+/, ''));
return ret;
}
// Look for the matching interface in all local interfaces
Object.keys(interfaces).some(name => {
return interfaces[name].some(addr => {
const subnet = ip.subnet(addr.address, addr.netmask);
const net = ipaddr.parseCIDR(`${addr.address}/${subnet.subnetMaskLength}`);
function v4() {
return internalIp('v4');
}
if (net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) {
ret = net[0].toString();
}
function v6() {
return internalIp('v6');
return Boolean(ret);
});
});
return ret ? ret : defaults[family];
}).catch(() => defaults[family]);
}
module.exports = v4;
module.exports.v4 = v4;
module.exports.v6 = v6;
module.exports.v6 = () => internalIp('v6');
module.exports.v4 = () => internalIp('v4');
{
"name": "internal-ip",
"version": "1.2.0",
"description": "Get your internal IPv4 or IPv6 address",
"license": "MIT",
"repository": "sindresorhus/internal-ip",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bin": "cli.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"cli.js"
],
"keywords": [
"cli-app",
"cli",
"bin",
"ip",
"ipv4",
"ipv6",
"address",
"internal",
"local",
"machine"
],
"dependencies": {
"meow": "^3.3.0"
},
"devDependencies": {
"ava": "*",
"is-ip": "^1.0.0",
"xo": "*"
}
"name": "internal-ip",
"version": "2.0.0",
"description": "Get your internal IP address",
"license": "MIT",
"repository": "sindresorhus/internal-ip",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"ip",
"ipv6",
"ipv4",
"address",
"internal",
"local",
"machine",
"system",
"net",
"gateway"
],
"dependencies": {
"default-gateway": "^2.0.0",
"ip": "^1.1.5",
"ipaddr.js": "^1.4.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
}
# internal-ip [![Build Status](https://travis-ci.org/sindresorhus/internal-ip.svg?branch=master)](https://travis-ci.org/sindresorhus/internal-ip)
> Get your internal IPv4 or IPv6 address
> Get your internal IP address
## CLI
## Install
```
$ npm install --global internal-ip
$ npm install internal-ip
```
```
$ internal-ip --help
Usage
$ internal-ip
## Usage
Options
-4, --ipv4 Return the IPv4 address (default)
-6, --ipv6 Return the IPv6 address
```js
const internalIp = require('internal-ip');
Example
$ internal-ip
192.168.0.123
$ internal-ip -6
fe80::200:f8ff:fe21:67cf
```
internalIp.v6().then(ip => {
console.log(ip);
//=> 'fe80::1'
});
## API
internalIp.v4().then(ip => {
console.log(ip);
//=> '10.0.0.79'
});
```
$ npm install --save internal-ip
```
```js
var internalIp = require('internal-ip');
In the case no address can be determined, `::1` or `127.0.0.1` will be returned as a fallback. If you think this is incorrect, please open an [issue](https://github.com/sindresorhus/internal-ip/issues/new).
internalIp.v4();
//=> '192.168.0.123'
internalIp.v6();
//=> 'fe80::200:f8ff:fe21:67cf'
```
## Related
See [public-ip](https://github.com/sindresorhus/public-ip) or [ipify](https://github.com/sindresorhus/ipify) to get your external IP address.
- [internal-ip-cli](https://github.com/sindresorhus/internal-ip-cli) - CLI for this module
- [public-ip](https://github.com/sindresorhus/public-ip) - Get your public IP address

@@ -54,2 +40,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc