Comparing version 0.3.2 to 0.4.0
@@ -9,2 +9,9 @@ "use strict"; | ||
var public_ip_urls = [ | ||
'http://checkip.dyndns.org', | ||
'http://wtfismyip.com/text', | ||
'http://ipecho.net/plain', | ||
'http://ifconfig.me/ip' | ||
]; | ||
function is_ip_address(str) { | ||
@@ -14,5 +21,3 @@ return ip_regex.test(str); | ||
function nic_by_name(name, cb) { | ||
os_functions.get_network_interfaces_list(function(err, list) { | ||
@@ -28,3 +33,2 @@ if (err) return cb(err); | ||
}); | ||
}; | ||
@@ -34,9 +38,2 @@ | ||
var default_urls = [ | ||
'checkip.dyndns.org', | ||
'http://wtfismyip.com/text', | ||
'http://ipecho.net/plain', | ||
'http://ifconfig.me/ip' | ||
]; | ||
if (typeof options == 'function') { // no options passed | ||
@@ -47,3 +44,3 @@ cb = options; | ||
var urls = options.urls || default_urls; | ||
var urls = options.urls || public_ip_urls; | ||
@@ -68,3 +65,2 @@ function get(i) { | ||
exports.get_private_ip = function(cb) { | ||
os_functions.get_network_interfaces_list(function(err, list) { | ||
@@ -88,7 +84,5 @@ if (err || !list) | ||
}); | ||
}; | ||
exports.get_gateway_ip = function(cb) { | ||
os_functions.get_active_network_interface_name(function(err, nic_name) { | ||
@@ -105,7 +99,5 @@ if (err || nic_name.trim() == '') | ||
}); | ||
}; | ||
exports.get_active_interface = function(cb) { | ||
os_functions.get_active_network_interface_name(function(err, nic_name) { | ||
@@ -130,3 +122,2 @@ if (err || !nic_name) return cb(err || new Error("No active interfaces detected.")); | ||
}); | ||
}; | ||
@@ -136,1 +127,2 @@ | ||
exports.mac_address_for = os_functions.mac_address_for; | ||
exports.gateway_ip_for = os_functions.gateway_ip_for; |
@@ -42,3 +42,3 @@ "use strict"; | ||
exports.gateway_ip_for = function(nic_name, cb) { | ||
trim_exec("ip r | grep " + nic_name + " | grep default | cut -d ' ' -f 3", cb); | ||
trim_exec("ip r | grep " + nic_name + " | grep default | cut -d ' ' -f 3 | head -1", cb); | ||
}; | ||
@@ -45,0 +45,0 @@ |
@@ -39,9 +39,22 @@ "use strict"; | ||
var list = [], | ||
var count, | ||
list = [], | ||
node_nics = os.networkInterfaces(); | ||
function done() { | ||
--count || callback(null, list); | ||
} | ||
function set_gateway(obj) { | ||
exports.gateway_ip_for(obj.name, function(err, res) { | ||
obj.gateway_ip = res && res != '' ? res : null; | ||
done(); | ||
}) | ||
} | ||
wmic.get_list('nic', function(err, nics) { | ||
if (err) return callback(err); | ||
nics.forEach(function(nic){ | ||
count = nics.length; | ||
nics.forEach(function(nic) { | ||
if (nic.Name && nic.NetConnectionID != '' && nic.MACAddress != '') { | ||
@@ -61,3 +74,3 @@ | ||
node_nic.forEach(function(type){ | ||
node_nic.forEach(function(type) { | ||
if (type.family == 'IPv4') { | ||
@@ -69,8 +82,9 @@ obj.ip_address = type.address; | ||
list.push(obj); | ||
set_gateway(obj); | ||
} else { | ||
done(); | ||
} | ||
}) | ||
callback(null, list); | ||
}); | ||
}; |
{ | ||
"name": "network", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Cross platform network utilities for Node.js (gateway_ip, MAC address, etc)", | ||
@@ -14,2 +14,3 @@ "main": "./lib/index.js", | ||
"async": "^1.5.2", | ||
"commander": "2.9.0", | ||
"needle": "1.1.2", | ||
@@ -16,0 +17,0 @@ "wmic": "^0.1.0" |
@@ -95,3 +95,3 @@ Network Utilies for Node.js | ||
netmask: '255.255.255.0', | ||
gateway_ip: '10.0.1.1' // only on OS X and Linux | ||
gateway_ip: '10.0.1.1' | ||
}, | ||
@@ -108,6 +108,2 @@ { ... }, { ... }] | ||
# TODO | ||
- Find a way to get the gateway IP for interfaces on Windows. Help wanted! | ||
# Copyright | ||
@@ -114,0 +110,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17930
366
4
114
+ Addedcommander@2.9.0
+ Addedcommander@2.9.0(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)