-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 1.15 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
#!/usr/bin/env node
import ping from 'ping';
import fetch from 'node-fetch';
import logUpdate from 'log-update';
import 'colors';
const url = 'https://api.steampowered.com/ISteamApps/GetSDRConfig/v1?appid=730';
main();
async function main() {
logUpdate('Fetching Servers'.yellow);
const servers = await fetchServers();
logUpdate(`Fetched ${servers.length} Servers`.green);
logUpdate.done();
for (const server of servers) {
logUpdate('Pinging'.green, `${server.name}`.bgWhite);
let ping = await pingServer(server.relays[ 0 ]);
if (ping === 'unknown') { logUpdate(`${server.name} did not respond`.red) }
else { logUpdate(`${server.name}`.bold, `${ping}ms`.italic); }
logUpdate.done();
}
};
async function pingServer(ip) {
return (await ping.promise.probe(ip)).time;
}
async function fetchServers() {
const { pops } = await fetch(url).then(res => res.json());
const servers = [];
Object.keys(pops).forEach(a => {
const pop = pops[ a ];
if (!pop.relays || !pop.relays.length)
return;
servers.push({
name: pop.desc,
relays: pop.relays.map(b => b.ipv4)
});
});
return servers;
}
export default main;