Skip to content

Instantly share code, notes, and snippets.

@zined
Created December 10, 2012 15:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zined/4251427 to your computer and use it in GitHub Desktop.
Save zined/4251427 to your computer and use it in GitHub Desktop.
ugly ugly :)
var https = require('https');
var tuples = new Array(
Math.floor(Math.random(254)*100),
Math.floor(Math.random(254)*100),
Math.floor(Math.random(254)*100),
Math.floor(Math.random(254)*100));
var ip = tuples.join('.');
var MAX_URLS = 30;
var urls = new Array();
var query = 'blar';
var offset = 0;
var fetchResults = function()
{
var url = 'https://ajax.googleapis.com/ajax/services/search/web?v=1.0'+
'&userip='+ ip +
'&q='+ encodeURIComponent(query) +
'&start='+ encodeURIComponent(offset);
// console.log('fetching query '+ query +' with offset of '+ offset);
https.get(url, function(response)
{
var tmpResults = '';
response.on('data', function (data) {
tmpResults += data;
});
response.on('end', function() {
results = JSON.parse(tmpResults);
var res = results.responseData;
if (res == null) {
console.log('TOS abuse ;-)');
return;
}
var i;
for (i=0;i<res.results.length;++i) {
urls.push(res.results[i]['visibleUrl']);
++offset;
}
if (urls.length < MAX_URLS) {
fetchResults();
} else {
//console.log('DONE!. fetched '+ urls.length +' urls');
var tree = new Object();
var j;
// dns like structure is sweet
for (j=0;j<urls.length;++j) {
var tmp = new String(urls[j]).split('.');
if (typeof(tree[tmp[tmp.length-1]]) == 'undefined')
tree[tmp[tmp.length-1]] = new Object();
tree[tmp[tmp.length-1]][tmp[tmp.length-2]] = 1;
}
for (tld in tree) {
for (domain in tree[tld]) {
console.log(domain +'.'+ tld);
}
}
}
});
});
}
fetchResults();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment