import * as os from 'os'

class IPUtil {

    getLocalIP(): string {
        let ifaces = os.networkInterfaces();
        let result = '127.0.0.1'
        Object.keys(ifaces).forEach(function (ifname) {
            ifaces[ifname].forEach(function (iface) {
                if ('IPv4' !== iface.family || iface.internal !== false) {
                    return;
                }
                result = iface.address;
                return;
            });
        });
        return result
    }
}

export default new IPUtil()