Skip to content

Commit

Permalink
fix: Make host IP extractor Node 18 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
mvsde committed May 3, 2022
1 parent 67cfaa6 commit db66632
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/get-host-ips.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import { networkInterfaces } from 'os'

/**
* Check if network interface address is usable.
* @param {import('os').NetworkInterfaceInfo} address
* @returns {boolean}
*/
function isUsableAddress (address) {
if (address.internal) {
return false
}

if (address.family === 'IPv4') {
return true
}

if (address.family === 4) {
return true
}
}

/**
* Get a list of all IPv4 IPs associated with the host
* @returns {string[]} List of IPv4 IPs
*/
export default function () {
return Object.values(networkInterfaces())
.flat()
.filter(address => !address.internal && address.family === 'IPv4')
.filter(isUsableAddress)
.map(address => address.address)
}

0 comments on commit db66632

Please sign in to comment.