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';
import fs from 'fs';
import _ from 'lodash';
let current = parseInt(process.env.CURRENT || '0', 36);
const max = parseInt(process.env.MAX || 'ZZZZ', 36);
let current = parseInt(process.env.CURRENT) || 0;
const max = parseInt(process.env.MAX) || 26 * 26 * 26 * 26 - 1;
const parallel = parseInt(process.env.PARALLEL) || 10;
const urlPrefix = process.env.URL_PREFIX;
const useCode = async (n: number) => {
let code = n.toString(36).toUpperCase();
if (code.length < 4) {
code = '0'.repeat(4 - code.length) + code;
function toCode(n: number) {
let code = '';
for (let i = 0; i < 4; i++) {
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 {
const result = await axios.get(`http://www.clco.cc/${code}`, {
const result = await axios.get(`${urlPrefix}${code}`, {
responseType: 'text',
validateStatus: (c) => c < 400 || c === 404,
validateStatus: (c) => c === 200,
timeout: parseInt(process.env.TIMEOUT) || 10000,
});
if (result.status === 404) {
console.log(`Bad ${code}`);
if (!result.data?.includes('<title>Create VPS &mdash; CLOUDCONE</title>')) {
console.log(`Bad ${n}-${code}`);
} else {
const data = {
status: result.status,
headers: result.headers,
data: result.data,
};
console.log(`Good ${code}: ${JSON.stringify(data)}`);
console.log(`Good ${n}-${code}: ${JSON.stringify(data)}`);
await fs.promises.writeFile(
`data/${n}-${code}.json`,
`data/$${code}.json`,
JSON.stringify(data, null, 2),
);
return true;
}
} catch (e) {
console.error(`Failed ${code}: ${e.message}`);
}
return false;
};
async function main() {
while (current <= max) {
const start = current;
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);
await Promise.all(ranges.map(useCode));
const results = await Promise.all(ranges.map(useCode));
if (results.some((result) => result)) {
break;
}
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