Created
November 7, 2022 02:02
-
-
Save NickColley/82bf1c023a467f3772ae25b5b1a1dcad to your computer and use it in GitHub Desktop.
Get the ooo domains
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
import { writeFile } from "node:fs/promises"; | |
import { promisify } from "node:util"; | |
import fetch from "node-fetch"; | |
import logUpdate from "log-update"; | |
import logSymbols from "log-symbols"; | |
import { stringify } from "csv"; | |
const toCSV = promisify(stringify); | |
let count = 0; | |
let max = 100; | |
let timeoutTime = 10; // seconds; | |
const prefixesToCheck = ["https://", "https://www.", "http://", "http://www."]; | |
async function getURL(url, count) { | |
const controller = new AbortController(); | |
const timeoutReference = setTimeout( | |
() => controller.abort(), | |
timeoutTime * 1000 | |
); | |
logUpdate(count, logSymbols.info, url); | |
const response = await fetch(url, { | |
method: "HEAD", | |
signal: controller.signal, | |
}); | |
if (!response.ok) { | |
throw new Error(`HTTP error! status: ${response.status}`); | |
} | |
return response.url; | |
} | |
let successful = []; | |
while (count++ <= max) { | |
const url = `${Array(count).fill("o").join("")}.ooo`; | |
logUpdate(count, logSymbols.info, url); | |
try { | |
const result = await Promise.any( | |
prefixesToCheck.map((prefix) => getURL(prefix + url, count)) | |
); | |
logUpdate(count, logSymbols.success, url, result); | |
successful.push([url, result, "Found"]); | |
} catch (aggregate) { | |
const error = [ | |
...new Set(aggregate.errors.map((error) => error.code || error.type)), | |
].join("\\,"); | |
logUpdate(count, logSymbols.error, url, error); | |
successful.push([url, "None", error]); | |
} | |
logUpdate.done(); | |
} | |
const columns = { | |
originalURL: "Original URL", | |
url: "Found URL", | |
result: "Result", | |
}; | |
const csv = await toCSV(successful, { header: true, columns: columns }); | |
await writeFile("ooo.csv", csv); | |
console.log("ooo.csv saved"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment