Commit 4a1b0752 authored by nanahira's avatar nanahira

hunter

parent 68bd3eda
Pipeline #11599 passed with stage
in 23 seconds
...@@ -2,48 +2,60 @@ import axios from 'axios'; ...@@ -2,48 +2,60 @@ import axios from 'axios';
import fs from 'fs'; import fs from 'fs';
import _ from 'lodash'; import _ from 'lodash';
let current = parseInt(process.env.CURRENT || '0', 36); let current = parseInt(process.env.CURRENT) || 0;
const max = parseInt(process.env.MAX || 'ZZZZ', 36); const max = parseInt(process.env.MAX) || 26 * 26 * 26 * 26 - 1;
const parallel = parseInt(process.env.PARALLEL) || 10; const parallel = parseInt(process.env.PARALLEL) || 10;
const urlPrefix = process.env.URL_PREFIX;
const useCode = async (n: number) => { function toCode(n: number) {
let code = n.toString(36).toUpperCase(); let code = '';
if (code.length < 4) { for (let i = 0; i < 4; i++) {
code = '0'.repeat(4 - code.length) + code; code = String.fromCharCode((n % 26) + 'a'.charCodeAt(0)) + code;
n = Math.floor(n / 26);
} }
console.log(`Trying ${code}`); return code;
}
const useCode = async (n: number) => {
const code = toCode(n);
console.log(`Trying ${n}: ${code}`);
try { try {
const result = await axios.get(`http://www.clco.cc/${code}`, { const result = await axios.get(`${urlPrefix}${code}`, {
responseType: 'text', responseType: 'text',
validateStatus: (c) => c < 400 || c === 404, validateStatus: (c) => c === 200,
timeout: parseInt(process.env.TIMEOUT) || 10000, timeout: parseInt(process.env.TIMEOUT) || 10000,
}); });
if (result.status === 404) { if (!result.data?.includes('<title>Create VPS &mdash; CLOUDCONE</title>')) {
console.log(`Bad ${code}`); console.log(`Bad ${n}-${code}`);
} else { } else {
const data = { const data = {
status: result.status, status: result.status,
headers: result.headers, headers: result.headers,
data: result.data, data: result.data,
}; };
console.log(`Good ${code}: ${JSON.stringify(data)}`); console.log(`Good ${n}-${code}: ${JSON.stringify(data)}`);
await fs.promises.writeFile( await fs.promises.writeFile(
`data/${n}-${code}.json`, `data/$${code}.json`,
JSON.stringify(data, null, 2), JSON.stringify(data, null, 2),
); );
return true;
} }
} catch (e) { } catch (e) {
console.error(`Failed ${code}: ${e.message}`); console.error(`Failed ${code}: ${e.message}`);
} }
return false;
}; };
async function main() { async function main() {
while (current <= max) { while (current <= max) {
const start = current; const start = current;
const end = Math.min(current + parallel, max + 1); const end = Math.min(current + parallel, max + 1);
console.log(`Running ${start} - ${end - 1}`); console.log(`Running from ${start} to ${end - 1}`);
const ranges = _.range(start, end); const ranges = _.range(start, end);
await Promise.all(ranges.map(useCode)); const results = await Promise.all(ranges.map(useCode));
if (results.some((result) => result)) {
break;
}
current = end; current = end;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment