if (sections[0] === '') { while (sections.length < 8) sections.unshift('0');
} elseif (sections[sections.length - 1] === '') { while (sections.length < 8) sections.push('0');
} elseif (sections.length < 8) { for (i = 0; i < sections.length && sections[i] !== ''; i++); var argv = [ i, 1 ]; for (i = 9 - sections.length; i > 0; i--) {
argv.push('0');
}
sections.splice.apply(sections, argv);
}
result = buff || Buffer.alloc(offset + 16); for (i = 0; i < sections.length; i++) { var word = parseInt(sections[i], 16);
result[offset++] = (word >> 8) & 0xff;
result[offset++] = word & 0xff;
}
}
if (!result) { throw Error('Invalid ip address: ' + ip);
}
var result = []; if (length === 4) { // IPv4 for (var i = 0; i < length; i++) {
result.push(buff[offset + i]);
}
result = result.join('.');
} elseif (length === 16) { // IPv6 for (var i = 0; i < length; i += 2) {
result.push(buff.readUInt16BE(offset + i).toString(16));
}
result = result.join(':');
result = result.replace(/(^|:)0(:0)*:0(:|$)/, '$1::$3');
result = result.replace(/:{3,4}/, '::');
}
return result;
};
var ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/; var ipv6Regex =
/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;
ip.loopback = function(family) { // // Default to `ipv4` //
family = _normalizeFamily(family);
if (family !== 'ipv4' && family !== 'ipv6') { thrownew Error('family must be ipv4 or ipv6');
}
return family === 'ipv4' ? '127.0.0.1' : 'fe80::1';
};
// // ### function address (name, family) // #### @name {string|'public'|'private'} **Optional** Name or security // of the network interface. // #### @family {ipv4|ipv6} **Optional** IP family of the address (defaults // to ipv4). // // Returns the address for the network interface on the current system with // the specified `name`: // * String: First `family` address of the interface. // If not found see `undefined`. // * 'public': the first public ip address of family. // * 'private': the first private ip address of family. // * undefined: First address with `ipv4` or loopback address `127.0.0.1`. //
ip.address = function(name, family) { var interfaces = os.networkInterfaces(); var all;
// // Default to `ipv4` //
family = _normalizeFamily(family);
// // If a specific network interface has been named, // return the address. // if (name && name !== 'private' && name !== 'public') { var res = interfaces[name].filter(function(details) { var itemFamily = details.family.toLowerCase(); return itemFamily === family;
}); if (res.length === 0) return undefined; return res[0].address;
}
var all = Object.keys(interfaces).map(function (nic) { // // Note: name will only be `public` or `private` // when this is called. // var addresses = interfaces[nic].filter(function (details) {
details.family = details.family.toLowerCase(); if (details.family !== family || ip.isLoopback(details.address)) { returnfalse;
} elseif (!name) { returntrue;
}
return name === 'public' ? ip.isPrivate(details.address) :
ip.isPublic(details.address);
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.