-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
112 lines (91 loc) · 2.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const csvToJson = require("csvtojson");
const fs = require("fs");
const axios = require("axios").default;
const FormData = require("form-data");
const args = process.argv.splice(2);
if (args.length < 1) {
console.log("No filepath given. Use it as a first parameter.");
process.exit(1);
}
const filePath = args[0];
const delimiter = args[1];
const topLevelFile = args[2];
let writeStream;
csvToJson({ delimiter: delimiter })
.fromFile(filePath)
.then(jsonObj => {
let domainBases = [];
let domains = [];
let tlds = getTlds(topLevelFile);
jsonObj.forEach(obj => {
let arr = [];
Object.keys(obj).forEach(key => arr.push(obj[key]));
let perms = permute(arr);
perms = perms.map(perm => perm.join(""));
domainBases.push(perms);
});
domainBases = domainBases.flat();
domainBases.forEach(base => {
tlds.forEach(tld => {
domains.push(`${base}.${tld}`);
});
});
initTable();
checkDomains(domains);
});
async function checkDomains(domains) {
length = domains.length;
for(let i = 0; i < length; i++) {
console.log(`Progress: ${i+1}/${length} | Currently checking: ${domains[i]}`);
let result = await doRequest(domains[i]);
writeStream.write(`\n| ${result.domain} | ${result.active === '0' ? "No" : "Yes"} |`);
}
writeStream.close();
}
function getTlds(path) {
let content = fs.readFileSync(path).toString();
let tlds = content.split(",");
tlds = tlds.map(tld => tld.trim());
return tlds;
}
function permute(permutation) {
var length = permutation.length,
result = [permutation.slice()],
c = new Array(length).fill(0),
i = 1, k, p;
while (i < length) {
if (c[i] < i) {
k = i % 2 && c[i];
p = permutation[i];
permutation[i] = permutation[k];
permutation[k] = p;
++c[i];
i = 1;
result.push(permutation.slice());
} else {
c[i] = 0;
++i;
}
}
return result;
}
function doRequest(domain) {
return new Promise((resolve, reject) => {
let bodyForm = new FormData();
bodyForm.append("pendingSiteAnalysis", "9b80555e77cf9c6495a092f6bb35db65e5d3a0416114510b70b746b538ceaa0a");
axios({
method: "post",
url: `https://who.is/api/whois/getDomainSiteAnalysis/` + domain,
data: bodyForm,
headers: { "Content-Type": "multipart/form-data" },
})
.then(resp => {
resolve({domain: domain, active: resp.data.active});
});
});
}
function initTable() {
writeStream = fs.createWriteStream("table.md");
writeStream.write("| Domain | Taken |");
writeStream.write("\n| ------ | ----- |");
}