-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (60 loc) · 2.12 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
const fs = require('fs');
const whoiser = require('whoiser')
// Read a list of domains from a file, one domain per line
const domainsFile = 'domainsToCheck.txt';
fs.readFile(domainsFile, 'utf8', async (err, data) => {
if (err) {
console.error(`Error reading file ${domainsFile}: ${err}`);
return;
}
const domains = data.split('\n').map(domain => domain.trim());
// Check if each domain is available
const checked = await checkDomains(domains);
// get the freeDomains.json file
const freeDomainsFile = require('./freeDomains.json');
// merge the free domains with the new free domains
const newFreeDomains = [...freeDomainsFile, ...checked];
// remove duplicates
const uniqueFreeDomains = [...new Set(newFreeDomains)];
// write the new free domains to the file
fs.writeFile('freeDomains.json', JSON.stringify(uniqueFreeDomains, null, 2), err => {
if (err) {
console.error(`Error writing file ${freeDomainsFile}: ${err}`);
return;
}
console.log(`Successfully wrote ${uniqueFreeDomains.length} domains to ${freeDomainsFile}`);
})
});
async function checkDomains(domains) {
const freeDomains = [];
for (domain of domains) {
// skip empty lines
if (!domain) continue;
const result = await whois(domain);
let regex = /Status:\s+(.*)active/;
if (result.match(regex)) {
console.log(`${domain} is not available`);
continue
}
let regex2 = /free/;
if (result.match(regex2)) {
freeDomains.push(domain);
console.log(`${domain} is available`);
}
}
return freeDomains;
}
async function whois(domain){
const result = await whoiser.domain(domain, {
// host: server,
timeout: 1500,
raw: true,
});
const raw = result['whois.domain-registry.nl'].__raw
// if raw has requests per second exceeded call again and wait 1 second
if (raw.match(/Requests per second exceeded/)) {
await new Promise(resolve => setTimeout(resolve, 1000));
return whois(domain);
}
return raw;
}