Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ ip.loopback = function (family) {
ip.address = function (name, family) {
const interfaces = os.networkInterfaces();

// Node version 18.x after, os.networkInterfaces() returns { ... family: {4|6} }, not { ... family: {IPv4|IPv6} }
// [NodeJS Docs 18.x os.html#osnetworkinterfaces](https://nodejs.org/docs/latest-v18.x/api/os.html#osnetworkinterfaces)
// [NodeJS Docs 17.x os.html#osnetworkinterfaces](https://nodejs.org/docs/latest-v17.x/api/os.html#osnetworkinterfaces)
for (let name in interfaces) {
interfaces[name].forEach(function(details) {
if (typeof details.family === 'number') {
details.family = 'IPv' + details.family;
}
});
}

//
// Default to `ipv4`
//
Expand Down