fugadalcontrollo/routes/tor.js
2018-07-24 00:29:12 +02:00

31 lines
758 B
JavaScript

var express = require('express');
var router = express.Router();
const dns = require('dns').promises;
function isExitNode (ip) {
ip = ip.split('.').reverse().join('.');
const domain = ip + '.8080.235.126.68.51.ip-port.exitlist.torproject.org'
console.log(domain);
return dns.lookup(domain, {}).then(ret => {
if (ret.address === '127.0.0.2') return true;
return false;
}).catch( e => false )
}
router.get('/', (req, res) => {
const source_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log(' son qui, ', req.url, ' ', source_ip);
isExitNode(source_ip).then( isExit => {
if (isExit) {
res.render('torok');
} else {
res.render('tornook');
}
});
});
module.exports = router;