Comparing version 0.0.11 to 0.0.12
@@ -5,3 +5,2 @@ "use strict"; | ||
// by Tomas Pollak - http://forkhq.com | ||
////////////////////////////////////////// | ||
@@ -11,2 +10,19 @@ var os = require('os'), | ||
// | ||
// helpers | ||
////////////////////////////////////////// | ||
function determine_nic_type(str) { | ||
return str.match(/Ethernet/) | ||
? 'Wired' | ||
: str.match(/Wi-?Fi|AirPort/i) | ||
? 'Wireless' | ||
: str.match(/FireWire/) | ||
? 'FireWire' | ||
: str.match(/Thunderbolt/) | ||
? 'Thunderbolt' | ||
: 'Other'; | ||
} | ||
exports.get_active_network_interface_name = function(cb) { | ||
@@ -62,27 +78,24 @@ var cmd = "netstat -rn | grep UG | awk '{print $6}'"; | ||
var parts = block.match(/Port: (.+)/); | ||
if (!parts) return; | ||
var parts = block.match(/Port: (.+)/), | ||
mac = block.match(/Address: ([A-Fa-f0-9:-]+)/), | ||
name = block.match(/Device: (\w+)/); | ||
var port = parts[1], | ||
type = port.match(/Ethernet/) ? 'Wired': port.match(/Wi-?Fi|AirPort/i) ? 'Wireless' : port; | ||
if (!parts || !mac || !name) return; | ||
if (type == 'Wired' || type == 'Wireless') { | ||
var obj = {}, | ||
port = parts[1]; | ||
var obj = { | ||
ip_address: null, | ||
type: type | ||
obj.name = name[1]; | ||
obj.desc = port; | ||
obj.type = determine_nic_type(port); | ||
obj.ip_address = null; | ||
obj.mac_address = mac[1]; | ||
(nics[obj.name] || []).forEach(function(type) { | ||
if (type.family == 'IPv4') { | ||
obj.ip_address = type.address; | ||
} | ||
}); | ||
obj.name = block.match(/Device: (\w+)/)[1]; | ||
obj.mac_address = block.match(/Address: ([A-Fa-f0-9:-]+)/)[1]; | ||
(nics[obj.name] || []).forEach(function(type) { | ||
if (type.family == 'IPv4') { | ||
obj.ip_address = type.address; | ||
} | ||
}); | ||
list.push(obj); | ||
} | ||
list.push(obj); | ||
}) | ||
@@ -89,0 +102,0 @@ |
{ | ||
"name": "network", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Cross platform network utilities for Node.js (gateway_ip, MAC address, etc)", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
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
13785
320