(family: 4 | 6 | null = null)
| 13 | * @param family - 4 for IPv4, 6 for IPv6, or null for all. |
| 14 | */ |
| 15 | export function fetchInterfaces(family: 4 | 6 | null = null): os.NetworkInterfaceInfo[] { |
| 16 | let familyValue: (4 | 6 | string)[] | null = null; |
| 17 | if (family === 4) { |
| 18 | familyValue = [4, 'IPv4']; |
| 19 | } else if (family === 6) { |
| 20 | familyValue = [6, 'IPv6']; |
| 21 | } |
| 22 | const ifaces = Object.values(os.networkInterfaces()).filter(Boolean) as os.NetworkInterfaceInfo[][]; |
| 23 | return ifaces.flat().filter((info) => !familyValue || familyValue.includes(info.family as 4 | 6 | string)); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Returns true if the address is a broadcast IP (0.0.0.0 or ::). |
no outgoing calls
no test coverage detected