internal-ip
Advanced tools
Comparing version 1.0.1 to 1.1.0
20
cli.js
@@ -6,10 +6,20 @@ #!/usr/bin/env node | ||
meow({ | ||
var cli = meow({ | ||
help: [ | ||
'Example', | ||
'Usage', | ||
' $ internal-ip', | ||
' 192.168.0.123' | ||
].join('\n') | ||
'', | ||
'Options', | ||
' --ipv6 Return the IPv6 address instead of IPv4', | ||
'', | ||
'Examples', | ||
' $ internal-ip', | ||
' 192.168.0.123', | ||
' $ internal-ip --ipv6', | ||
' fe80::200:f8ff:fe21:67cf' | ||
] | ||
}); | ||
console.log(internalIp()); | ||
var fn = cli.flags.ipv6 ? 'v6' : 'v4'; | ||
console.log(internalIp[fn]()); |
32
index.js
'use strict'; | ||
var os = require('os'); | ||
module.exports = function () { | ||
var ret = '127.0.0.1'; | ||
var type = { | ||
v4: { | ||
def: '127.0.0.1', | ||
family: 'IPv4' | ||
}, | ||
v6: { | ||
def: '::1', | ||
family: 'IPv6' | ||
} | ||
}; | ||
function internalIp(version) { | ||
var options = type[version]; | ||
var ret = options.def; | ||
var interfaces = os.networkInterfaces(); | ||
@@ -10,3 +22,3 @@ | ||
interfaces[el].forEach(function (el2) { | ||
if (!el2.internal && el2.family === 'IPv4') { | ||
if (!el2.internal && el2.family === options.family) { | ||
ret = el2.address; | ||
@@ -18,2 +30,14 @@ } | ||
return ret; | ||
}; | ||
} | ||
function v4() { | ||
return internalIp('v4'); | ||
} | ||
function v6() { | ||
return internalIp('v6'); | ||
} | ||
module.exports = v4; | ||
module.exports.v4 = v4; | ||
module.exports.v6 = v6; |
{ | ||
"name": "internal-ip", | ||
"version": "1.0.1", | ||
"description": "Get your internal IPv4 address", | ||
"version": "1.1.0", | ||
"description": "Get your internal IPv4 or IPv6 address", | ||
"license": "MIT", | ||
@@ -17,3 +17,3 @@ "repository": "sindresorhus/internal-ip", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "xo && ava" | ||
}, | ||
@@ -30,2 +30,3 @@ "files": [ | ||
"ipv4", | ||
"ipv6", | ||
"address", | ||
@@ -37,8 +38,9 @@ "internal", | ||
"dependencies": { | ||
"meow": "^3.1.0" | ||
"meow": "^3.3.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "0.0.4", | ||
"is-ip": "^1.0.0" | ||
"ava": "*", | ||
"is-ip": "^1.0.0", | ||
"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 address | ||
> Get your internal IPv4 or IPv6 address | ||
@@ -15,5 +15,13 @@ | ||
Usage | ||
$ internal-ip | ||
Options | ||
--ipv6 Return the IPv6 address instead of IPv4 | ||
Example | ||
$ internal-ip | ||
192.168.0.123 | ||
$ internal-ip --ipv6 | ||
fe80::200:f8ff:fe21:67cf | ||
``` | ||
@@ -31,4 +39,7 @@ | ||
internalIp(); | ||
//=> 192.168.0.123 | ||
internalIp.v4(); | ||
//=> '192.168.0.123' | ||
internalIp.v6(); | ||
//=> 'fe80::200:f8ff:fe21:67cf' | ||
``` | ||
@@ -35,0 +46,0 @@ |
3774
55
54
3
Updatedmeow@^3.3.0