Advertisement
Guest User

ip

a guest
Nov 12th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var os = require('os');
  4. var ifaces = os.networkInterfaces();
  5.  
  6. Object.keys(ifaces).forEach(function (ifname) {
  7.   var alias = 0;
  8.  
  9.   ifaces[ifname].forEach(function (iface) {
  10.     if ('IPv4' !== iface.family || iface.internal !== false) {
  11.       // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
  12.       return;
  13.     }
  14.  
  15.     if (alias >= 1) {
  16.       // this single interface has multiple ipv4 addresses
  17.       console.log(ifname + ':' + alias, iface.address);
  18.     } else {
  19.       // this interface has only one ipv4 adress
  20.       console.log(ifname, iface.address);
  21.     }
  22.     ++alias;
  23.   });
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement