feat: connect 消息上报 local_ip 和 external_ip

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-21 08:18:27 +08:00
parent af5248f2a6
commit 878f3592bf
8 changed files with 1595 additions and 1392 deletions

View File

@@ -2,6 +2,7 @@
const { execSync } = require('child_process');
const fs = require('fs');
const os = require('os');
const log = require('./logger');
const AP_SSID_PREFIX = 'ClawBox-';
@@ -223,6 +224,29 @@ function isWifiStaConnected() {
return false;
}
/**
* 获取本机所有非回环 IPv4 地址,逗号拼接返回
* 例:'192.168.1.100' 或 '192.168.1.100,10.0.0.5'
*/
function getLocalIps() {
try {
const ifaces = os.networkInterfaces();
const ips = [];
for (const [name, addrs] of Object.entries(ifaces)) {
if (!addrs) continue;
for (const addr of addrs) {
if (addr.family === 'IPv4' && !addr.internal) {
ips.push(addr.address);
}
}
}
return ips.length > 0 ? ips.join(',') : null;
} catch (e) {
log.warn('network', '获取本机 IP 失败:', e.message);
return null;
}
}
module.exports = {
hasInternet,
hasWiredCarrier,
@@ -234,4 +258,5 @@ module.exports = {
startAP,
stopAP,
AP_IP,
getLocalIps,
};