-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (43 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const geoip = require('geoip-lite');
const { exec } = require('child_process');
// Get your IP address
const myIp = require('my-ip')();
// Define the command you want to run
const cmd = `"C:\\\\Program Files\\\\Wireshark\\\\tshark.exe" -i Wi-fi -Y "stun && ip.src != ${myIp}"`;
// Execute the command
const process = exec(cmd);
// Create a function to get the geolocation of an IP address
function getIpLocation(ip) {
const geo = geoip.lookup(ip);
if (!geo) {
return "Unknown";
}
const { country, ll, city } = geo;
return `${country}, ${ll}, ${city}`;
}
const ipLocationMap = new Map();
process.stdout.on('data', (data) => {
const columns = data.toString().split(/\s+/);
if (columns.includes('STUN') || columns.includes('UDP')) {
const srcIpIndex = columns.indexOf('→') - 1;
const srcIp = columns[srcIpIndex];
try {
let location = ipLocationMap.get(srcIp);
if (!location) {
location = getIpLocation(srcIp);
ipLocationMap.set(srcIp, location);
}
console.log(`>>> ${location}`);
} catch (error) {
console.error(`Error processing IP address ${srcIp}: ${error}`);
}
}
});
// Listen for errors
process.stderr.on('data', (data) => {
console.log(`${data}`);
});
// Listen for process exit
process.on('exit', (code) => {
console.log(`Child process exited with code ${code}`);
});