Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ta1al committed Aug 10, 2022
0 parents commit 82697f2
Show file tree
Hide file tree
Showing 4 changed files with 527 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import ping from 'ping';
import fetch from 'node-fetch';
import logUpdate from 'log-update';
import color from 'colors';
const url = 'https://steamcdn-a.akamaihd.net/apps/sdr/network_config.json';

(async function () {
logUpdate(color.yellow('Fetching Servers'));
const servers = await fetchServers();
logUpdate(color.green(`Fetched ${servers.length} Servers`));
logUpdate.done();
for (const server of servers) {
logUpdate(color.green('Pinging'), color.bgWhite(server.name));
let ping = await pingServer(server.relays[ 0 ]);
if (ping === 'unknown') { logUpdate(color.red(`${server.name} did not respond`)) }
else { logUpdate(color.bold(`${server.name}`), color.italic(`${ping}ms`)); }
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;
}
Loading

0 comments on commit 82697f2

Please sign in to comment.