-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 887 Bytes
/
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
const express = require('express');
const dns = require('dns');
const app = express();
const config = require('./config.json');
const blockList = new Set(config.blockList || []);
app.get('/', (req, res) => {
const domain = req.query.domain;
if (!domain || blockList.has(domain)) {
return res.status(400).send('Disallowed');
}
dns.resolve4(domain, (err, addresses) => {
if (err) {
return res.status(403).send('DNS resolution failed');
}
const predefinedIP = config.ip;
if (addresses.includes(predefinedIP) && ((domain.match(/\./g) || []).length) <= 3) {
return res.status(200).send('DNS is pointing to the predefined IP');
} else {
return res.status(403).send('DNS is not pointing to the predefined IP');
}
});
});
const PORT = 5555;
app.listen(PORT, () => {
console.log(`TLS check server is running on port ${PORT}`);
});