Created
October 23, 2012 00:07
-
-
Save Jimbly/3935714 to your computer and use it in GitHub Desktop.
Failed attempt at IP filtering.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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