"use strict";

let os = require('os');

module.exports = function getIP() {
  let ifaces = os.networkInterfaces();
  let ips = [];
  Object.keys(ifaces).forEach(ifname => {
    let a = ifaces[ifname].map(iface => {
      if ('IPv4' !== iface.family || iface.internal !== false) {
        return null;
      }

      return iface.address;
    }).filter(a => a);
    ips = ips.concat(a);
  });
  ips.push('127.0.0.1');
  return ips[0];
};