anti_api / test /test-get-ip.js
liuw15's picture
小追加
f5e9acd
raw
history blame contribute delete
544 Bytes
import os from 'os';
function getLocalIp() {
const interfaces = os.networkInterfaces();
console.log(JSON.stringify(interfaces, null, 2))
if (interfaces.WLAN) {
for (const inter of interfaces.WLAN) {
if (inter.family === 'IPv4' && !inter.internal) {
return inter.address;
}
}
} else if (interfaces.wlan2) {
for (const inter of interfaces.wlan2) {
if (inter.family === 'IPv4' && !inter.internal) {
return inter.address;
}
}
return '127.0.0.1';
}
}
console.log(getLocalIp());