diagnostics: correlate duplicate guest addresses with live traffic and DHCP

This commit is contained in:
jfeng committed 2026-10-22 16:37:57 +00:00
1 parent f8235b55b0
commit 64add2bc68
1 file changed
+17 -10
+17 -10
View File
@@ -25,14 +25,21 @@ try {
console.log('TEMP-RECORDS',JSON.stringify((db.tempAccess||[]).map(t=>({device:hash(t.mac),createdAt:t.createdAt,expiresAt:t.expiresAt,revoked:t.revoked}))));
} catch(e){console.log('DB-ERROR',redact(e.message));}
console.log('DEPLOYMENT-OBSERVATION',JSON.stringify({clientProbesInstalled:fs.readFileSync('/app/public/index.html','utf8').includes('verifyClientInternet'),startOnPixInstalled:fs.readFileSync('/app/public/index.html','utf8').includes("sessionStorage.setItem('pendingPix'")}));
const database=JSON.parse(fs.readFileSync(config.dataDir+'/db.json','utf8'));
console.log('CLIENT-OBSERVATIONS',JSON.stringify((database.tempAccess||[]).map(t=>({device:hash(t.mac),expiresAt:t.expiresAt,probe:t.clientProbe||null}))));
const garden=(await rosCommand(['/ip/hotspot/walled-garden/ip/print','=.proplist=comment,dst-address,dst-port,protocol,disabled'])).map(object).filter(r=>r.comment==='pix: portal pagamento');
console.log('LOCAL-PORTAL-EXCEPTION',JSON.stringify(garden));
for(const hostname of ['www.gstatic.com','www.apple.com']){
try {
const result=(await rosCommand(['/ping','=address='+hostname,'=count=1'])).map(object);
console.log('ROUTER-DNS-TEST',JSON.stringify({hostname,resolved:result.some(r=>/^[0-9a-f:.]+$/i.test(r.host||'')),received:result.at(-1)?.received||'0'}));
}catch(e){console.log('ROUTER-DNS-ERROR',hostname,redact(e.message));}
const hosts=(await rosCommand(['/ip/hotspot/host/print','=.proplist=.id,address,to-address,mac-address,server,authorized,bypassed,uptime,idle-time,bytes-in,bytes-out,packets-in,packets-out'])).map(object).filter(h=>h.server===config.mikrotik.server);
const macs=[...new Set(hosts.map(h=>h['mac-address']))];
for(const mac of macs){
const rows=hosts.filter(h=>h['mac-address']===mac);
console.log('HOST-ALIASES',redact(JSON.stringify(rows.map(r=>({...r,addressHash:hash(r.address),toAddressHash:hash(r['to-address'])})))));
for(const [label,path] of [['LEASES','/ip/dhcp-server/lease/print'],['ARP','/ip/arp/print']]){
try{console.log(label,redact(JSON.stringify((await rosCommand([path,'?mac-address='+mac,'=.proplist=address,active-address,status,server,last-seen,interface,complete'])).map(object))));}
catch(e){console.log(label+'-ERROR',redact(e.message));}
}
}
const connections=(await rosCommand(['/ip/firewall/connection/print','=.proplist=src-address,dst-address,seen-reply,protocol,tcp-state'])).map(object);
for(const h of hosts){
const c=connections.filter(c=>(c['src-address']||'').split(':')[0]===h.address);
const external=c.filter(c=>!/^(10\\.|192\\.168\\.|172\\.(1[6-9]|2\\d|3[01])\\.)/.test(c['dst-address']||''));
console.log('ALIAS-CONNECTIONS',JSON.stringify({addressHash:hash(h.address),device:hash(h['mac-address']),count:c.length,external:external.length,withReplies:external.filter(c=>c['seen-reply']==='true').length,dnsReplies:external.filter(c=>(c['dst-address']||'').endsWith(':53')&&c['seen-reply']==='true').length}));
}
console.log('DHCP-SERVERS',redact(JSON.stringify((await rosCommand(['/ip/dhcp-server/print','=.proplist=name,interface,disabled,address-pool'])).map(object))));
console.log('HOTSPOT-SETTINGS',JSON.stringify((await rosCommand(['/ip/hotspot/print','=.proplist=name,addresses-per-mac,idle-timeout,keepalive-timeout,interface'])).map(object)));