-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (36 loc) · 1.09 KB
/
app.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
const dns = require('node:dns');
const fs = require('fs');
const path = require('path');
function getNameServer ( $domain ) {
dns.resolveNs( $domain, ( err, addresses ) => {
if ( err ) {
console.error(err);
return;
}
console.log( $domain + " : " + addresses[0] );
saveToFile ( $domain, addresses[0] )
} );
}
function getDomains () {
const filePath = path.join(__dirname, 'zoneSearch.csv');
const fileContent = fs.readFileSync(filePath, 'utf-8');
const lines = fileContent.split( '\n' );
let tld = lines.map( line => line.split( ';' )[0].replace( /"/g, '' ) );
tld.shift();
return tld;
}
function saveToFile ( domain, nameServer ) {
const filePath = path.join( __dirname, 'nameservers.csv' );
const fileContent = `${ domain };${ nameServer }\n`;
fs.appendFileSync( filePath, fileContent );
}
const tlds = getDomains();
tlds.forEach( ( tld ) => {
dns.resolveNs( tld, ( err, addresses ) => {
if (err) {
saveToFile( tld, "no such host" );
return;
}
saveToFile( tld, addresses[0] );
} );
} );