diff --git a/lib/iputils.js b/lib/iputils.js index 900b4d8f..e71bac0d 100644 --- a/lib/iputils.js +++ b/lib/iputils.js @@ -70,6 +70,24 @@ var getIpAddresses = (function() { var os = require('os'); + var isIpv6WeCareAbout = (function() { + var ignoredTopSegments = { + "fe80": true, + "ff00": true, + "fc00": true, + "fec0": true, + }; + return function(address) { + // honestly I don't really understand ipv6 and which address make no sense. It seems + // like the top few bits might stay but + + // should probably check for 0 using ip6addr + + var topSegment = address.substr(0, 4).toLowerCase(); + return ignoredTopSegments[topSegment] === undefined; + } + }()); + return function() { var now = Date.now(); if (!addresses || now - lastRead > cacheTime) { @@ -78,9 +96,13 @@ var getIpAddresses = (function() { addresses = []; for (var k in interfaces) { for (var k2 in interfaces[k]) { - var address = interfaces[k][k2]; - if (address.family === 'IPv4' && !address.internal) { - addresses.push(address.address); + var iface = interfaces[k][k2]; + if (!iface.internal) { + if (iface.family === 'IPv4') { + addresses.push(iface.address); + } else if (iface.family === 'IPv6' && isIpv6WeCareAbout(iface.address)) { + addresses.push("[" + iface.address + "]"); + } } } }