mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-06 07:53:54 +00:00
29 lines
738 B
TypeScript
29 lines
738 B
TypeScript
import { networkInterfaces } from 'os';
|
|
|
|
/**
|
|
* @description Gets information on IPV4 non-internal interfaces
|
|
* @returns {array} - Array of objects {name: ip}
|
|
*/
|
|
export function getNetworkInterfaces(): { name: string; address: string }[] {
|
|
const nets = networkInterfaces();
|
|
const results: { name: string; address: string }[] = [];
|
|
|
|
for (const name of Object.keys(nets)) {
|
|
const netObjects = nets[name];
|
|
if (!netObjects) {
|
|
continue;
|
|
}
|
|
for (const net of netObjects) {
|
|
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
|
if (net.family === 'IPv4' && !net.internal) {
|
|
results.push({
|
|
name,
|
|
address: net.address,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|