Skip to content

Instantly share code, notes, and snippets.

@Jimbly
Created October 23, 2012 00:07
Show Gist options
  • Save Jimbly/3935714 to your computer and use it in GitHub Desktop.
Save Jimbly/3935714 to your computer and use it in GitHub Desktop.
Failed attempt at IP filtering.
var dns = require('dns');
var http = require('http');
var https = require('https');
var blocked = ['207.171.163.193'];
var user_supplied_hostname = 'www.cloudpartytime.com';
dns.lookup(user_supplied_hostname, function(err, address) {
console.log('DNS lookup returned ' + address);
if (blocked.indexOf(address) !== -1) {
return console.log('Blocked access to ' + address);
}
var req = http.get({
host: address,
path: '/',
headers: { host: user_supplied_hostname }
}, function(res) {
console.log("Got response: " + res.statusCode);
if (res.statusCode !== 200) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
console.log('body: ' + chunk);
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment