forked from brozeph/simple-socks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateServerConnectionFilter.js
More file actions
31 lines (25 loc) · 990 Bytes
/
createServerConnectionFilter.js
File metadata and controls
31 lines (25 loc) · 990 Bytes
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
const
dns = require('dns'),
socks5 = require('../dist/socks5'),
server = socks5.createServer({
connectionFilter : function (destination, origin, callback) {
console.log('Attempting to connect to...');
console.log(destination);
console.log();
console.log('Inbound origin of request is...');
console.log(origin);
return dns.reverse(destination.address, function (err, hostnames) {
if (!hostnames || !hostnames.length || !/github/.test(hostnames[0])) {
console.log('Not allowing connection to %s:%s', destination.address, destination.port);
return callback(new Error('connection to destination address is denied (only github is allowed)'));
}
return callback();
});
}
});
server.on('connectionFilter', function (destination, origin, err) {
console.log('connection to %s:%s has been denied (only requests to github are allowed)', destination.address, destination.port);
console.error(err);
});
// start listening!
server.listen(1080);