fugadalcontrollo/routes/tor.js
2018-07-21 01:14:47 +02:00

29 lines
706 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.connection.remoteAddress;
console.log(' son qui, ', req.url);
isExitNode(source_ip).then( isExit => {
if (isExit) {
res.render('torok');
} else {
res.render('tornook');
}
});
});
module.exports = router;