forked from GreatWizard/lan-play-status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-flags.js
39 lines (35 loc) · 1.04 KB
/
update-flags.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
#!/usr/bin/env node
/* eslint-disable no-console */
const dns = require("dns");
const geoip = require("geoip-country");
const servers = require("./public/data/servers.json");
const updateData = async function(server) {
let { ip, port = "14451", flag, platform = "switch", type = "rust" } = server;
return await new Promise((resolve, reject) => {
dns.resolve4(ip, (err, addresses) => {
if (err) reject(err);
let result = {
ip,
port,
flag,
platform,
type
};
if (addresses && addresses.length > 0) {
let lookup = geoip.lookup(addresses[0]);
let detected = (lookup && lookup.country.toLowerCase()) || undefined;
if (result.flag !== detected) {
console.log(` * "${ip}" must be updated to the flag "${detected}".`);
result.flag = detected;
}
}
resolve(result);
});
});
};
const getData = async () => {
return Promise.all(servers.map(server => updateData(server)));
};
getData().then(data => {
console.log(data);
});