@stacksjs/whois 0.66.0 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/constants.ts DELETED
@@ -1,325 +0,0 @@
1
- export const IANA_CHK_URL: string = 'https://www.iana.org/whois?q='
2
-
3
- export const PARAMETERS: Record<string, string> = {
4
- 'whois.denic.de': '-T dn,ace',
5
- 'whois.nic.fr': '-V Md5.2',
6
- }
7
-
8
- export const SERVERS: Record<string, string> = {
9
- 'br.com': 'whois.centralnic.net',
10
- 'cn.com': 'whois.centralnic.net',
11
- 'de.com': 'whois.centralnic.net',
12
- 'eu.com': 'whois.centralnic.net',
13
- 'gb.com': 'whois.centralnic.net',
14
- 'gb.net': 'whois.centralnic.net',
15
- 'gr.com': 'whois.centralnic.net',
16
- 'hu.com': 'whois.centralnic.net',
17
- 'in.net': 'whois.centralnic.net',
18
- 'no.com': 'whois.centralnic.net',
19
- 'qc.com': 'whois.centralnic.net',
20
- 'ru.com': 'whois.centralnic.net',
21
- 'sa.com': 'whois.centralnic.net',
22
- 'se.com': 'whois.centralnic.net',
23
- 'se.net': 'whois.centralnic.net',
24
- 'uk.com': 'whois.centralnic.net',
25
- 'uk.net': 'whois.centralnic.net',
26
- 'us.com': 'whois.centralnic.net',
27
- 'uy.com': 'whois.centralnic.net',
28
- 'za.com': 'whois.centralnic.net',
29
- 'jpn.com': 'whois.centralnic.ne',
30
- 'web.com': 'whois.centralnic.ne',
31
- 'com': 'whois.verisign-grs.com',
32
- 'za.net': 'whois.za.net',
33
- 'net': 'whois.verisign-grs.com',
34
- 'eu.org': 'whois.eu.org',
35
- 'za.org': 'whois.za.org',
36
- 'org': 'whois.pir.org',
37
- 'llyw.cymru': 'whois.nic.llyw.cymru',
38
- 'gov.scot': 'whois.nic.gov.scot',
39
- 'gov.wales': 'whois.nic.gov.wales',
40
- 'edu': 'whois.educause.edu',
41
- 'gov': 'whois.dotgov.gov',
42
- 'int': 'whois.iana.org',
43
- 'e164.arpa': 'whois.ripe.net',
44
- 'arpa': 'whois.iana.org',
45
- 'aero': 'whois.aero',
46
- 'asia': 'whois.nic.asia',
47
- 'biz': 'whois.nic.biz',
48
- 'cat': 'whois.nic.cat',
49
- 'coop': 'whois.nic.coop',
50
- 'info': 'whois.afilias.net',
51
- 'jobs': 'whois.nic.jobs',
52
- 'mobi': 'whois.afilias.net',
53
- 'museum': 'whois.nic.museum',
54
- 'name': 'whois.nic.name',
55
- 'post': 'whois.dotpostregistry.net',
56
- 'pro': 'whois.nic.pro',
57
- 'tel': 'whois.nic.tel',
58
- 'travel': 'whois.nic.travel',
59
- 'xxx': 'whois.nic.xxx',
60
- 'ac': 'whois.nic.ac',
61
- 'ae': 'whois.aeda.net.ae',
62
- 'af': 'whois.nic.af',
63
- 'ag': 'whois.nic.ag',
64
- 'ai': 'whois.nic.ai',
65
- 'am': 'whois.amnic.net',
66
- 'ar': 'whois.nic.ar',
67
- 'as': 'whois.nic.as',
68
- 'priv.at': 'whois.nic.priv.at',
69
- 'at': 'whois.nic.at',
70
- 'au': 'whois.auda.org.au',
71
- 'aw': 'whois.nic.aw',
72
- 'ax': 'whois.ax',
73
- 'be': 'whois.dns.be',
74
- 'bf': 'whois.registre.bf',
75
- 'bg': 'whois.register.bg',
76
- 'bh': 'whois.nic.bh',
77
- 'bi': 'whois1.nic.bi',
78
- 'bj': 'whois.nic.bj',
79
- 'bm': 'whois.afilias-srs.net',
80
- 'bn': 'whois.bnnic.bn',
81
- 'bo': 'whois.nic.bo',
82
- 'br': 'whois.registro.br',
83
- 'by': 'whois.cctld.by',
84
- 'bw': 'whois.nic.net.bw',
85
- 'bz': 'whois.afilias-grs.info',
86
- 'co.ca': 'whois.co.ca',
87
- 'ca': 'whois.cira.ca',
88
- 'cc': 'ccwhois.verisign-grs.com',
89
- 'cd': 'whois.nic.cd',
90
- 'ch': 'whois.nic.ch',
91
- 'ci': 'whois.nic.ci',
92
- 'cl': 'whois.nic.cl',
93
- 'cm': 'whois.netcom.cm',
94
- 'edu.cn': 'whois.edu.cn',
95
- 'cn': 'whois.cnnic.cn',
96
- 'uk.co': 'whois.uk.co',
97
- 'co': 'whois.nic.co',
98
- 'cr': 'whois.nic.cr',
99
- 'cx': 'whois.nic.cx',
100
- 'cz': 'whois.nic.cz',
101
- 'de': 'whois.denic.de',
102
- 'dk': 'whois.dk-hostmaster.dk',
103
- 'dm': 'whois.dmdomains.dm',
104
- 'do': 'whois.nic.do',
105
- 'dz': 'whois.nic.dz',
106
- 'ec': 'whois.nic.ec',
107
- 'ee': 'whois.tld.ee',
108
- 'eu': 'whois.eu',
109
- 'fi': 'whois.fi',
110
- 'fj': 'www.whois.fj',
111
- 'fm': 'whois.nic.fm',
112
- 'fo': 'whois.nic.fo',
113
- 'fr': 'whois.nic.fr',
114
- 'gd': 'whois.nic.gd',
115
- 'ge': 'whois.nic.ge',
116
- 'gf': 'whois.mediaserv.net',
117
- 'gg': 'whois.gg',
118
- 'gh': 'whois.nic.gh',
119
- 'gi': 'whois2.afilias-grs.net',
120
- 'gl': 'whois.nic.gl',
121
- 'gp': 'whois.nic.gp',
122
- 'gq': 'whois.dominio.gq',
123
- 'gs': 'whois.nic.gs',
124
- 'gy': 'whois.registry.gy',
125
- 'hk': 'whois.hkirc.hk',
126
- 'hm': 'whois.registry.hm',
127
- 'hn': 'whois.nic.hn',
128
- 'hr': 'whois.dns.hr',
129
- 'ht': 'whois.nic.ht',
130
- 'hu': 'whois.nic.hu',
131
- 'id': 'whois.id',
132
- 'ie': 'whois.weare.ie',
133
- 'il': 'whois.isoc.org.il',
134
- 'im': 'whois.nic.im',
135
- 'in': 'whois.registry.in',
136
- 'io': 'whois.nic.io',
137
- 'iq': 'whois.cmc.iq',
138
- 'ir': 'whois.nic.ir',
139
- 'is': 'whois.isnic.is',
140
- 'it': 'whois.nic.it',
141
- 'je': 'whois.je',
142
- 'jp': 'whois.jprs.jp',
143
- 'ke': 'whois.kenic.or.ke',
144
- 'kg': 'whois.kg',
145
- 'ki': 'whois.nic.ki',
146
- 'kn': 'whois.nic.kn',
147
- 'kr': 'whois.kr',
148
- 'kw': 'whois.nic.kw',
149
- 'ky': 'whois.kyregistry.ky',
150
- 'kz': 'whois.nic.kz',
151
- 'la': 'whois.nic.la',
152
- 'lb': 'whois.lbdr.org.lb',
153
- 'lc': 'whois2.afilias-grs.net',
154
- 'li': 'whois.nic.li',
155
- 'lk': 'whois.nic.lk',
156
- 'ls': 'whois.nic.ls',
157
- 'lt': 'whois.domreg.lt',
158
- 'lu': 'whois.dns.lu',
159
- 'lv': 'whois.nic.lv',
160
- 'ly': 'whois.nic.ly',
161
- 'ma': 'whois.registre.ma',
162
- 'md': 'whois.nic.md',
163
- 'me': 'whois.nic.me',
164
- 'mg': 'whois.nic.mg',
165
- 'mk': 'whois.marnet.mk',
166
- 'ml': 'whois.dot.ml',
167
- 'mm': 'whois.registry.gov.mm',
168
- 'mn': 'whois.nic.mn',
169
- 'mq': 'whois.mediaserv.net',
170
- 'mr': 'whois.nic.mr',
171
- 'ms': 'whois.nic.ms',
172
- 'mt': 'whois.nic.org.mt',
173
- 'mu': 'whois.nic.mu',
174
- 'mw': 'whois.nic.mw',
175
- 'mx': 'whois.mx',
176
- 'my': 'whois.mynic.my',
177
- 'mz': 'whois.nic.mz',
178
- 'na': 'whois.na-nic.com.na',
179
- 'nc': 'whois.nc',
180
- 'nf': 'whois.nic.nf',
181
- 'ng': 'whois.nic.net.ng',
182
- 'nl': 'whois.domain-registry.nl',
183
- 'no': 'whois.norid.no',
184
- 'nu': 'whois.iis.nu',
185
- 'nz': 'whois.irs.net.nz',
186
- 'om': 'whois.registry.om',
187
- 'pe': 'kero.yachay.pe',
188
- 'pf': 'whois.registry.pf',
189
- 'pk': 'whois.pknic.net.pk',
190
- 'co.pl': 'whois.co.pl',
191
- 'pl': 'whois.dns.pl',
192
- 'pm': 'whois.nic.pm',
193
- 'pr': 'whois.afilias-srs.net',
194
- 'ps': 'whois.pnina.ps',
195
- 'pt': 'whois.dns.pt',
196
- 'pw': 'whois.nic.pw',
197
- 'qa': 'whois.registry.qa',
198
- 're': 'whois.nic.re',
199
- 'ro': 'whois.rotld.ro',
200
- 'rs': 'whois.rnids.rs',
201
- 'ac.ru': 'whois.free.net',
202
- 'edu.ru': 'whois.informika.ru',
203
- 'com.ru': 'whois.flexireg.net',
204
- 'msk.ru': 'whois.flexireg.net',
205
- 'net.ru': 'whois.nic.net.ru',
206
- 'nov.ru': 'whois.flexireg.net',
207
- 'org.ru': 'whois.nic.net.ru',
208
- 'pp.ru': 'whois.nic.net.ru',
209
- 'spb.ru': 'whois.flexireg.net',
210
- 'ru': 'whois.tcinet.ru',
211
- 'rw': 'whois.ricta.org.rw',
212
- 'sa': 'whois.nic.net.sa',
213
- 'sb': 'whois.nic.net.sb',
214
- 'sc': 'whois2.afilias-grs.net',
215
- 'sd': 'whois.sdnic.sd',
216
- 'se': 'whois.iis.se',
217
- 'sg': 'whois.sgnic.sg',
218
- 'sh': 'whois.nic.sh',
219
- 'si': 'whois.register.si',
220
- 'sk': 'whois.sk-nic.sk',
221
- 'sl': 'whois.nic.sl',
222
- 'sm': 'whois.nic.sm',
223
- 'sn': 'whois.nic.sn',
224
- 'so': 'whois.nic.so',
225
- 'ss': 'whois.nic.ss',
226
- 'st': 'whois.nic.st',
227
- 'msk.su': 'whois.flexireg.net',
228
- 'nov.su': 'whois.flexireg.net',
229
- 'spb.su': 'whois.flexireg.net',
230
- 'su': 'whois.tcinet.ru',
231
- 'sx': 'whois.sx',
232
- 'sy': 'whois.tld.sy',
233
- 'tc': 'whois.nic.tc',
234
- 'td': 'whois.nic.td',
235
- 'tf': 'whois.nic.tf',
236
- 'tg': 'whois.nic.tg',
237
- 'th': 'whois.thnic.co.th',
238
- 'tk': 'whois.dot.tk',
239
- 'tl': 'whois.nic.tl',
240
- 'tm': 'whois.nic.tm',
241
- 'tn': 'whois.ati.tn',
242
- 'to': 'whois.tonic.to',
243
- 'tr': 'whois.trabis.gov.tr',
244
- 'tv': 'whois.nic.tv',
245
- 'tw': 'whois.twnic.net.tw',
246
- 'tz': 'whois.tznic.or.tz',
247
- 'biz.ua': 'whois.biz.ua',
248
- 'co.ua': 'whois.co.ua',
249
- 'pp.ua': 'whois.pp.ua',
250
- 'ua': 'whois.ua',
251
- 'ug': 'whois.co.ug',
252
- 'ac.uk': 'whois.nic.ac.uk',
253
- 'gov.uk': 'whois.gov.uk',
254
- 'uk': 'whois.nic.uk',
255
- 'fed.us': 'whois.nic.gov',
256
- 'us': 'whois.nic.us',
257
- 'uy': 'whois.nic.org.uy',
258
- 'uz': 'whois.cctld.uz',
259
- 'vc': 'whois2.afilias-grs.net',
260
- 've': 'whois.nic.ve',
261
- 'vg': 'whois.nic.vg',
262
- 'vu': 'whois.dnrs.vu',
263
- 'wf': 'whois.nic.wf',
264
- 'ws': 'whois.website.ws',
265
- 'yt': 'whois.nic.yt',
266
- 'ac.za': 'whois.ac.za',
267
- 'co.za': 'whois.registry.net.za',
268
- 'gov.za': 'whois.gov.za',
269
- 'net.za': 'net-whois.registry.net.za',
270
- 'org.za': 'org-whois.registry.net.za',
271
- 'web.za': 'web-whois.registry.net.za',
272
- 'zm': 'whois.zicta.zm',
273
- 'xn--2scrj9c': 'whois.registry.in',
274
- 'xn--3e0b707e': 'whois.kr',
275
- 'xn--3hcrj9c': 'whois.registry.in',
276
- 'xn--45br5cyl': 'whois.registry.in',
277
- 'xn--45brj9c': 'whois.registry.in',
278
- 'xn--4dbrk0ce': 'whois.isoc.org.il',
279
- 'xn--80ao21a': 'whois.nic.kz',
280
- 'xn--90a3ac': 'whois.rnids.rs',
281
- 'xn--90ae': 'whois.imena.bg',
282
- 'xn--90ais': 'whois.cctld.by',
283
- 'xn--clchc0ea0b2g2a9gcd': 'whois.sgnic.sg',
284
- 'xn--d1alf': 'whois.marnet.mk',
285
- 'xn--e1a4c': 'whois.eu',
286
- 'xn--fiqs8s': 'cwhois.cnnic.cn',
287
- 'xn--fiqz9s': 'cwhois.cnnic.cn',
288
- 'xn--fpcrj9c3d': 'whois.registry.in',
289
- 'xn--fzc2c9e2c': 'whois.nic.lk',
290
- 'xn--gecrj9c': 'whois.registry.in',
291
- 'xn--h2breg3eve': 'whois.registry.in',
292
- 'xn--h2brj9c8c': 'whois.registry.in',
293
- 'xn--h2brj9c': 'whois.registry.in',
294
- 'xn--j1amh': 'whois.dotukr.com',
295
- 'xn--j6w193g': 'whois.hkirc.hk',
296
- 'xn--kprw13d': 'whois.twnic.net.tw',
297
- 'xn--kpry57d': 'whois.twnic.net.tw',
298
- 'xn--lgbbat1ad8j': 'whois.nic.dz',
299
- 'xn--mgb9awbf': 'whois.registry.om',
300
- 'xn--mgba3a4f16a': 'whois.nic.ir',
301
- 'xn--mgbaam7a8h': 'whois.aeda.net.ae',
302
- 'xn--mgbah1a3hjkrd': 'whois.nic.mr',
303
- 'xn--mgbbh1a71e': 'whois.registry.in',
304
- 'xn--mgbbh1a': 'whois.registry.in',
305
- 'xn--mgberp4a5d4ar': 'whois.nic.net.sa',
306
- 'xn--mgbgu82a': 'whois.registry.in',
307
- 'xn--mgbtx2b': 'whois.cmc.iq',
308
- 'xn--mgbx4cd0ab': 'whois.mynic.my',
309
- 'xn--node': 'whois.itdc.ge',
310
- 'xn--o3cw4h': 'whois.thnic.co.th',
311
- 'xn--ogbpf8fl': 'whois.tld.sy',
312
- 'xn--p1ai': 'whois.tcinet.ru',
313
- 'xn--pgbs0dh': 'whois.ati.tn',
314
- 'xn--q7ce6a': 'whois.nic.la',
315
- 'xn--qxa6a': 'whois.eu',
316
- 'xn--rvc1e0am3e': 'whois.registry.in',
317
- 'xn--s9brj9c': 'whois.registry.in',
318
- 'xn--wgbh1c': 'whois.dotmasr.eg',
319
- 'xn--wgbl6a': 'whois.registry.qa',
320
- 'xn--xkc2al3hye2a': 'whois.nic.lk',
321
- 'xn--xkc2dl3a5ee0h': 'whois.registry.in',
322
- 'xn--y9a3aq': 'whois.amnic.net',
323
- 'xn--yfro4i67o': 'whois.sgnic.sg',
324
- 'xn--ygbi2ammx': 'whois.pnina.ps',
325
- }
package/src/index.ts DELETED
@@ -1,383 +0,0 @@
1
- import type { SocksClientOptions } from 'socks'
2
- import type { ProxyData, WhoIsOptions, WhoIsResponse } from './types'
3
- import Net from 'node:net'
4
- import { log } from '@stacksjs/logging'
5
- import fetch from 'node-fetch'
6
- import { SocksClient } from 'socks'
7
- import { IANA_CHK_URL, PARAMETERS, SERVERS } from './constants'
8
- import { ProxyType } from './types'
9
- import { shallowCopy } from './utils'
10
-
11
- /**
12
- * Find the WhoIs server for the TLD from IANA WhoIs service. The TLD is be searched and the HTML response is parsed to extract the WhoIs server
13
- *
14
- * @param tld TLD of the domain
15
- * @returns WhoIs server which hosts the information for the domains of the TLD
16
- */
17
- export async function findWhoIsServer(tld: string): Promise<string> {
18
- const chkURL = IANA_CHK_URL + tld
19
-
20
- try {
21
- const res = await fetch(chkURL)
22
- if (res.ok) {
23
- const body = await res.text()
24
- const server = body.match(/whois:\s+(\S+)/)
25
- if (server?.[1])
26
- return server[1]
27
- }
28
- }
29
- catch (err) {
30
- console.error('Error in getting WhoIs server data from IANA', err)
31
- }
32
-
33
- return ''
34
- }
35
-
36
- /**
37
- * Get whois server of the tld from servers list
38
- *
39
- * @param tld TLD of the domain
40
- * @returns WhoIs server which hosts the information for the domains of the TLD
41
- */
42
- export function getWhoIsServer(tld: keyof typeof SERVERS): string | undefined {
43
- if (tld === 'com')
44
- return 'whois.verisign-grs.com'
45
- return SERVERS[tld]
46
- }
47
-
48
- /**
49
- * Extract TLD from domain name.
50
- * If the TLD is in whois-servers.json file, then the TLD is returned.
51
- * If TLD is not found within the file, then determined by taking the last element after splitting the domain name from '.'
52
- *
53
- * @param domain Domain name
54
- * @returns TLD
55
- */
56
- export function getTLD(domain: string): keyof typeof SERVERS {
57
- const domainParts = domain.split('.')
58
- for (let i = domainParts.length - 1; i > 0; i--) {
59
- const possibleTLD = domainParts.slice(i).join('.') as keyof typeof SERVERS
60
- if (SERVERS[possibleTLD]) {
61
- return possibleTLD
62
- }
63
- }
64
- // If no match found in SERVERS, return the last part
65
- return domainParts[domainParts.length - 1] as keyof typeof SERVERS
66
- }
67
-
68
- // get whois query parameters if exist on parameters.json for whois server
69
- export function getParameters(server: string): string | undefined {
70
- return (PARAMETERS as { [key: string]: string })[server]
71
- }
72
-
73
- /**
74
- * Parse collected raw WhoIs data
75
- *
76
- * @class
77
- */
78
- export class WhoIsParser {
79
- /**
80
- * Iterated through the complete text and returns extracted values
81
- *
82
- * @param rawData raw text from WhoIs server
83
- * @param outputData Data which needs to be extracted from the raw text (key/value pairs). Keys are used to extract from raw text and values are filled.
84
- * @returns Filled {@link outputData}
85
- */
86
- private static iterParse(rawData: string, outputData: any) {
87
- let lastStr = ''
88
- let lastField: string | null = null
89
- let lastLetter = ''
90
-
91
- for (let i = 0; i < rawData.length; i++) {
92
- const letter = rawData[i]
93
- if (letter === '\n' || (lastLetter === ':' && letter === ' ')) {
94
- if (lastStr.trim() in outputData) {
95
- lastField = lastStr.trim()
96
- }
97
- else if (lastField !== null) {
98
- const x = lastStr.trim()
99
- if (x !== '') {
100
- const obj = outputData[lastField]
101
- if (Array.isArray(obj))
102
- obj.push(x)
103
- else outputData[lastField] = x
104
-
105
- lastField = null
106
- }
107
- }
108
- lastStr = ''
109
- }
110
- else if (letter !== ':') {
111
- lastStr = lastStr + letter
112
- }
113
- lastLetter = letter as string
114
- if (lastStr === 'Record maintained by' || lastStr === '>>>')
115
- break
116
- }
117
-
118
- return outputData
119
- }
120
-
121
- /**
122
- * Parse the raw WhoIs text and returns extracted values
123
- *
124
- * @param rawData raw text from WhoIs server
125
- * @param outputData Data which needs to be extracted from the raw text (key/value pairs). Keys are used to extract from raw text and values are filled.
126
- * @returns Filled {@link outputData}
127
- */
128
- public static parseData(rawData: string, outputData: any | null): any {
129
- if (!outputData) {
130
- outputData = {
131
- 'Domain Name': '',
132
- 'Creation Date': '',
133
- 'Updated Date': '',
134
- 'Registry Expiry Date': '',
135
- 'Domain Status': [],
136
- 'Registrar': '',
137
- }
138
- }
139
-
140
- outputData = WhoIsParser.iterParse(rawData, outputData)
141
-
142
- return outputData
143
- }
144
- }
145
-
146
- /**
147
- * Connects to the provided {@link server}:{@link port} through TCP (through a proxy if a proxy is given), run the WhoIs query and returns the response
148
- *
149
- * @param domain Domain name
150
- * @param queryOptions Query options which can be used with the specific WhoIs server to get the complete response
151
- * @param server WhoIs server
152
- * @param port WhoIs server port
153
- * @param encoding Encoding used by the WhoIs server
154
- * @param proxy {@link ProxyData}
155
- * @returns The {string} WhoIs response for the query. Empty string is returned for errors
156
- */
157
- export async function tcpWhois(
158
- domain: string,
159
- queryOptions: string,
160
- server: string,
161
- port: number,
162
- encoding: string,
163
- proxy: ProxyData | null,
164
- ): Promise<string> {
165
- const decoder = new TextDecoder(encoding)
166
- const encoder = new TextEncoder()
167
-
168
- if (!proxy) {
169
- const socket = new Net.Socket()
170
- return new Promise((resolve, reject) => {
171
- try {
172
- socket.connect({ port, host: server }, () => {
173
- if (queryOptions !== '')
174
- socket.write(encoder.encode(`${queryOptions} ${domain}\r\n`))
175
- else socket.write(encoder.encode(`${domain}\r\n`))
176
- })
177
-
178
- socket.on('data', (data) => {
179
- resolve(decoder.decode(data))
180
- })
181
-
182
- socket.on('error', (error) => {
183
- reject(error)
184
- })
185
- }
186
- catch (e) {
187
- reject(e)
188
- }
189
- })
190
- }
191
-
192
- const options: SocksClientOptions = {
193
- proxy: {
194
- host: proxy.ip,
195
- port: proxy.port,
196
- type: proxy.type === ProxyType.SOCKS5 ? 5 : 4,
197
- },
198
-
199
- command: 'connect',
200
-
201
- destination: {
202
- host: server,
203
- port,
204
- },
205
- }
206
-
207
- if (proxy.username && proxy.password) {
208
- options.proxy.userId = proxy.username
209
- options.proxy.password = proxy.password
210
- }
211
-
212
- return new Promise((resolve, reject) => {
213
- SocksClient.createConnection(options, (err, info) => {
214
- if (err) {
215
- reject(err)
216
- }
217
- else {
218
- if (!info)
219
- reject(new Error('No socket info received!'))
220
-
221
- if (queryOptions !== '') {
222
- info?.socket.write(encoder.encode(`${queryOptions} ${domain}\r\n`))
223
- }
224
- else {
225
- info?.socket.write(encoder.encode(`${domain}\r\n`))
226
- }
227
-
228
- info?.socket.on('data', (data) => {
229
- resolve(decoder.decode(data))
230
- })
231
-
232
- info?.socket.resume()
233
- }
234
- })
235
- })
236
- }
237
-
238
- /**
239
- * Collect WhoIs data for the mentioned {@link domain}. Parse the received response if {@link parse} is true, accordingly.
240
- *
241
- * @param domain Domain name
242
- * @param parse Whether the raw text needs to be parsed/formatted or not
243
- * @param options {@link WhoIsOptions}
244
- * @returns {@link WhoIsResponse} Returns a {@link WhoIsResponse} object which contains the raw text and parsed data (if parse is true)
245
- */
246
- export async function whois(
247
- domain: string,
248
- parse = false,
249
- options: WhoIsOptions | null = null,
250
- ): Promise<WhoIsResponse> {
251
- let tld: string
252
- let port = 43
253
- let server = ''
254
- let proxy: ProxyData | null
255
- let encoding = 'utf-8'
256
-
257
- if (!options) {
258
- tld = getTLD(domain)
259
- proxy = null
260
- }
261
- else {
262
- tld = options.tld ? options.tld : getTLD(domain)
263
- encoding = options.encoding ? options.encoding : 'utf-8'
264
- proxy = options.proxy ? options.proxy : null
265
- server = options.server ? options.server : ''
266
- port = options.serverPort ? options.serverPort : 43
267
- }
268
-
269
- if (server === '') {
270
- let serverData = getWhoIsServer(tld as keyof typeof SERVERS)
271
- if (!serverData) {
272
- log.debug(`No WhoIs server found for TLD: ${tld}! Attempting IANA WhoIs database for server!`)
273
- serverData = await findWhoIsServer(tld)
274
- if (!serverData) {
275
- log.debug('WhoIs server could not be found!')
276
- return {
277
- _raw: '',
278
- parsedData: null,
279
- }
280
- }
281
- log.debug(`WhoIs sever found for ${tld}: ${server}`)
282
- }
283
-
284
- server = serverData
285
- }
286
-
287
- const qOptions = getParameters(server)
288
- const queryOptions = qOptions || ''
289
-
290
- try {
291
- log.debug(`Attempting WHOIS lookup for ${domain} on server ${server}`)
292
- const rawData = await tcpWhois(domain, queryOptions, server, port, encoding, proxy)
293
- log.debug(`Raw WHOIS data received:`, rawData)
294
- if (!parse) {
295
- const parsedData = WhoIsParser.parseData(rawData, null)
296
- return {
297
- _raw: rawData,
298
- parsedData,
299
- }
300
- }
301
-
302
- let outputData: any | null = null
303
- if (options?.parseData)
304
- outputData = shallowCopy(options.parseData)
305
-
306
- try {
307
- const parsedData = WhoIsParser.parseData(rawData, outputData)
308
- return {
309
- _raw: rawData,
310
- parsedData,
311
- }
312
- }
313
- catch (err) {
314
- console.error('Error in parsing WhoIs data!', err)
315
- return {
316
- _raw: rawData,
317
- parsedData: null,
318
- }
319
- }
320
- }
321
- catch (err: any) {
322
- log.debug(`Error in WHOIS lookup for ${domain} on server ${server}`, err)
323
- return {
324
- _raw: '',
325
- parsedData: null,
326
- }
327
- }
328
- }
329
-
330
- export function lookup(domain: string, options: WhoIsOptions | null = null): Promise<WhoIsResponse> {
331
- log.debug(`Lookup called for ${domain}`)
332
- return whois(domain, true, options)
333
- }
334
-
335
- /**
336
- * Collects (and parse/format if set to be true) for the provided {@link domains}. If {@link parallel} is set to be true, multiple threads will be used to batch process the domains according to {@link threads} mentioned.
337
- * If <i>options.parsedData</i> is mentioned, then it will be used to parse <b>all</b> the responses.
338
- * If a proxy is mentioned in {@link options}, then the proxy will be used to collect <b>all</b> the WhoIs data.
339
- *
340
- * @param domains Domains Names
341
- * @param parallel Whether data should be collected parallally or not
342
- * @param threads Batch size (for parallel processing)
343
- * @param parse Whether the raw text needs to be parsed/formatted or not
344
- * @param options {@link WhoIsOptions}
345
- * @returns Array of {@link WhoIsResponse} for all the domains. Order is not guaranteed
346
- */
347
- export async function batchWhois(
348
- domains: string[],
349
- parallel = false,
350
- threads = 1,
351
- parse = false,
352
- options: WhoIsOptions | null = null,
353
- ): Promise<WhoIsResponse[]> {
354
- let response: WhoIsResponse[] = []
355
-
356
- if (parallel) {
357
- if (threads > domains.length)
358
- threads = domains.length
359
-
360
- for (let i = 0; i < domains.length; i += threads) {
361
- const batch = domains.slice(i, i + threads)
362
- response = await Promise.all(
363
- batch.map(async (domain) => {
364
- return await whois(domain, parse, options)
365
- }),
366
- )
367
- }
368
- }
369
- else {
370
- for (let i = 0; i < domains.length; i++) {
371
- const res = await whois(domains[i] as string, parse, options)
372
- response.push(res)
373
- }
374
- }
375
-
376
- return response
377
- }
378
-
379
- export * from './constants'
380
- export * from './types'
381
-
382
- export { SocksClient } from 'socks'
383
- export type { SocksClientOptions } from 'socks'