From 2f54848835e030ab0bac81d182386344018913b1 Mon Sep 17 00:00:00 2001 From: xadparo <45482148+xadparo@users.noreply.github.com> Date: Mon, 30 May 2022 18:29:00 +0900 Subject: [PATCH] fix: os.networkInterface result migrate --- lib/ip.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/ip.js b/lib/ip.js index 4b2adb5..f141519 100644 --- a/lib/ip.js +++ b/lib/ip.js @@ -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` //