Socket
Socket
Sign inDemoInstall

address

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

address - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

5

History.md
0.0.2 / 2013-08-08
==================
* use networkInterface() to get mac fix #3
0.0.1 / 2013-07-31

@@ -3,0 +8,0 @@ ==================

57

lib/address.js

@@ -28,18 +28,2 @@ /*!

function _getIP(family, interfaceName) {
var interfaces = os.networkInterfaces();
interfaceName = interfaceName || DEFAULT_INTERFACE;
for (var i = -1; i < 8; i++) {
var items = interfaces[interfaceName + (i >= 0 ? i : '')]; // support 'lo' and 'lo0'
if (items && items.length > 0) {
for (var j = 0; j < items.length; j++) {
var item = items[j];
if (item.family === family) {
return item.address;
}
}
}
}
}
/**

@@ -75,2 +59,27 @@ * Get all addresses.

address.interface = function (family, name) {
var interfaces = os.networkInterfaces();
name = name || DEFAULT_INTERFACE;
family = family || 'IPv4';
var networks;
for (var i = -1; i < 8; i++) {
var items = interfaces[name + (i >= 0 ? i : '')]; // support 'lo' and 'lo0'
if (items) {
networks = items;
break;
}
}
if (!networks || !networks.length) {
return;
}
for (var j = 0; j < networks.length; j++) {
var item = networks[j];
if (item.family === family) {
return item;
}
}
};
/**

@@ -83,3 +92,4 @@ * Get current machine IPv4

address.ip = function (interfaceName) {
return _getIP('IPv4', interfaceName);
var item = address.interface('IPv4', interfaceName);
return item && item.address;
};

@@ -94,3 +104,4 @@

address.ipv6 = function (interfaceName) {
return _getIP('IPv6', interfaceName);
var item = address.interface('IPv6', interfaceName);
return item && item.address;
};

@@ -177,6 +188,10 @@

var ip = address.ip(interfaceName);
if (!ip) {
var item = address.interface('IPv4', interfaceName);
if (!item) {
return callback();
}
if (item.mac) {
return callback(null, item.mac);
}

@@ -188,3 +203,3 @@ child.exec(IFCONFIG_CMD, {timeout: 5000}, function (err, stdout, stderr) {

var mac = getMAC(stdout || '', interfaceName, ip);
var mac = getMAC(stdout || '', interfaceName, item.address);
callback(null, mac);

@@ -191,0 +206,0 @@ });

{
"name": "address",
"version": "0.0.1",
"version": "0.0.2",
"description": "Get current machine IP, MAC and DNS servers.",

@@ -15,3 +15,3 @@ "main": "index.js",

"travis-cov": {
"threshold": 98
"threshold": 95
}

@@ -18,0 +18,0 @@ },

@@ -53,2 +53,9 @@ address [![Build Status](https://secure.travis-ci.org/fengmk2/address.png)](http://travis-ci.org/fengmk2/address) [![Coverage Status](https://coveralls.io/repos/fengmk2/address/badge.png)](https://coveralls.io/r/fengmk2/address)

### Get an interface info with family
```js
address.interface('IPv4', 'eth1');
// { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
```
### Get DNS servers

@@ -55,0 +62,0 @@

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