Skip to content

Commit 0b3f136

Browse files
committed
delete stales ips and add append ips for clients
1 parent 7011efd commit 0b3f136

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

index.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dotenv from 'dotenv';
22
import { neigh } from 'ip-wrapper';
3-
import { pingIP, arraysEqual, isMacAddress, isIp } from './utils.js';
3+
import { arraysEqual, isMacAddress, isIp } from './utils.js';
44

55
dotenv.config();
66

@@ -61,27 +61,14 @@ async function updateClients() {
6161
if (macAddresses.length === 0) return
6262

6363
const originalClientIps = client.ids.filter(id => isIp(id));
64-
let ipsForClient = [...originalClientIps];
64+
let ipsForClient = [];
6565

6666
macAddresses.forEach(mac => {
6767
if (neighborIPsByMAC[mac]) {
68-
ipsForClient = neighborIPsByMAC[mac];
68+
ipsForClient = [...ipsForClient, ...neighborIPsByMAC[mac]];
6969
}
7070
});
7171

72-
const pingResults = await Promise.all(ipsForClient.map(ip => pingIP(ip)));
73-
ipsForClient = ipsForClient.filter((ip, index) => {
74-
const isAlive = pingResults[index];
75-
if (isAlive) {
76-
if (staleIPs[ip]) {
77-
delete staleIPs[ip];
78-
}
79-
} else {
80-
staleIPs[ip] = (staleIPs[ip] || 0) + 1;
81-
}
82-
return isAlive || (staleIPs[ip] <= 100);
83-
});
84-
8572
const updatedIds = [...new Set([...ipsForClient])];
8673

8774
if (!arraysEqual(originalClientIps, updatedIds)) {

0 commit comments

Comments
 (0)