This particular (ugly) script generates all 3-character .cc domain permutations and searches for which ones are available for purchase using namecheapapi.com. It outputs to console and a file called output.txt.
Last active
July 14, 2022 20:07
-
-
Save MitchTalmadge/652f162f33585e2f49d8576d387adaf6 to your computer and use it in GitHub Desktop.
Batch Domain Lookup Script
This file contains hidden or 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
const fs = require('fs'); | |
var requestOptions = { | |
method: 'GET', | |
redirect: 'follow' | |
}; | |
const generate3CharacterPermutations = () => { | |
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; | |
const permutations = []; | |
for (let i = 0; i < characters.length; i++) { | |
for (let j = 0; j < characters.length; j++) { | |
for (let k = 0; k < characters.length; k++) { | |
permutations.push(characters[i] + characters[j] + characters[k]); | |
} | |
} | |
} | |
return permutations; | |
} | |
const searchDomains = (domains) => { | |
const url = "https://aftermarket.namecheapapi.com/domain/status?domain=" + domains.join(","); | |
return fetch(url, requestOptions) | |
.then(response => response.text()) | |
.then(result => { | |
const domains = JSON.parse(result).data; | |
const buynowDomains = domains.filter(domain => domain.type === 'buynow'); | |
const output = buynowDomains.map(d => `${d.domain} - $${d.price}`).join('\n') + '\n'; | |
// Print results to console and file | |
console.log(output); | |
fs.appendFileSync('output.txt', output); | |
}) | |
} | |
const main = () => { | |
const permutations = generate3CharacterPermutations(); | |
// Append .cc to each permutation | |
const permutationsWithCC = permutations.map(permutation => permutation + '.cc'); | |
// Split permutations into chunks of 10 | |
const chunkSize = 100; | |
const chunks = []; | |
for (let i = 0; i < permutationsWithCC.length; i += chunkSize) { | |
chunks.push(permutationsWithCC.slice(i, i + chunkSize)); | |
} | |
// For each chunk, make a request to the API | |
let promise = Promise.resolve(); | |
chunks.forEach(chunk => { | |
// Chain promises together... | |
promise = promise.then(() => searchDomains(chunk)); | |
}); | |
promise.catch(error => console.log('Error:', error)); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment