-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
68 lines (62 loc) · 1.97 KB
/
server.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var dnsd = require('dnsd');
var got = require("got");
var PORT = 5333;
var INTERFACEIP = '0.0.0.0'
var limit = 25; // max number of hosts
var addresses = [];
var fetchAddresses = function() {
got("http://explorer.bithereum.network/ext/connections?_=1549651810200")
.then(function(response) {
var data = {}
try {
data = JSON.parse(response.body);
} catch(e) {}
if (data.data) {
addresses = data.data.splice(0,limit).map(function(entry) {
return entry.address;
});
addresses = addresses.filter(function(entry) {
return [
"3.94.59.38",
"3.88.162.163",
"3.84.58.236"
].indexOf(entry.address) == -1
});
}
});
};
var handle = function(req, res) {
var question = req.question[0];
var hostname = question.name || "";
var length = hostname.length;
var ttl = Math.floor(Math.random() * 60);
console.log(question);
if (question.type == "A") {
// US (Mainnet)
if (hostname.indexOf("x9.us-dnsseed") === 0) {
for (var address in addresses) {
res.answer.push({name:hostname, type:'A', data: addresses[address], ttl:ttl});
}
fetchAddresses();
}
// Europe (Mainnet)
else if (hostname.indexOf("x9.eu-dnsseed") === 0) {
}
// Singapore (Mainnet)
else if (hostname.indexOf("x9.sg-dnsseed") === 0) {
}
// US (Testnet)
else if (hostname.indexOf("x9.us-testnet-dnsseed") === 0) {
}
// Europe (Testnet)
else if (hostname.indexOf("x9.eu-testnet-dnsseed") === 0) {
}
// Singapore (Testnet)
else if (hostname.indexOf("x9.sg-testnet-dnsseed") === 0) {
}
}
res.end()
};
fetchAddresses();
dnsd.createServer(handle).listen(PORT, INTERFACEIP);
console.log('DNS Server Running');