exports.getLocalIP = function () {
    const os = require('os');
    const osType = os.type(); //系统类型
    const netInfo = os.networkInterfaces(); //网络信息
    let ip = '';
    if (osType === 'Windows_NT') {
        for (let dev in netInfo) {
            //win7的网络信息中显示为本地连接，win10显示为以太网
            if (dev.indexOf("本地连接") != -1 || dev.indexOf("以太网") != -1 || dev.indexOf("WLAN") != -1) {
                for (let j = 0; j < netInfo[dev].length; j++) {
                    if (netInfo[dev][j].family === 'IPv4') {
                        ip = netInfo[dev][j].address;
                        if (ip) {
                            if (ip.indexOf("192.") != -1) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    } else if (osType === 'Linux') {
        if (netInfo.eth0) {
            for (let 索引 = 0; 索引 < netInfo.en0.length; 索引++) {
                ip = netInfo.en0[索引].address;
                if (netInfo.en0[索引].address.indexOf("192.") != -1) {
                    break
                }
            }
        } else {
            for (let 索引 = 0; 索引 < netInfo.eth0.length; 索引++) {
                ip = netInfo.eth0[索引].address;
                if (netInfo.eth0[索引].address.indexOf("192.") != -1) {
                    break
                }
            }
        }
    } else if (osType === 'Darwin') {
        for (let 索引 = 0; 索引 < netInfo.en0.length; 索引++) {
            ip = netInfo.en0[索引].address;
            if (netInfo.en0[索引].address.indexOf("192.") != -1) {
                break
            }
        }
    }
    return ip;
}