import * as os from 'os'

class IPUtils {

    /**
     * 获取本机IP地址
     */
    static getIPAdress() {
        let result = "";
        let interfaces = os.networkInterfaces();
        for (let devName in interfaces) {
            let iface = interfaces[devName];
            for (let i = 0; i < iface.length; i++) {
                let alias = iface[i];
                if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                    result = alias.address;
                }
            }
        }
        return result;
    }

}

export { IPUtils }