getLocalIp.ts 339 B

12345678910111213
  1. import { networkInterfaces } from 'os';
  2. export function getLocalIp(): string {
  3. const ips = networkInterfaces();
  4. let ip;
  5. Object.values(ips).forEach(el => {
  6. const matchIp = el?.find(element => element.family === 'IPv4');
  7. if (matchIp && matchIp.address !== '127.0.0.1') {
  8. ip = matchIp.address;
  9. }
  10. });
  11. return ip;
  12. }