@cleandns/whois-rdap 1.0.30 → 1.0.32
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/dist/index.js +5 -1
- package/dist/ip.d.ts +2 -0
- package/dist/ip.js +23 -0
- package/dist/utils/tldToRdap.js +8 -3
- package/package.json +1 -1
- package/src/index.ts +6 -1
- package/src/ip.ts +28 -0
- package/src/utils/tldToRdap.ts +8 -3
- package/whois.d.ts +12 -0
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseIpResponse } from "./ip.js";
|
|
1
2
|
import { determinePort43Domain, port43 } from "./port43.js";
|
|
2
3
|
import { findInObject } from "./utils/findInObject.js";
|
|
3
4
|
import { fixArrays } from "./utils/fixArrays.js";
|
|
@@ -31,7 +32,8 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
|
|
|
31
32
|
}
|
|
32
33
|
url = "https://rdap.org";
|
|
33
34
|
}
|
|
34
|
-
const
|
|
35
|
+
const type = domain.match(/[^\d.]/) ? "domain" : "ip";
|
|
36
|
+
const thinRdap = `${url}/${type}/${domain}`;
|
|
35
37
|
// console.log(`fetching thin RDAP: ${thinRdap}`);
|
|
36
38
|
let thinResponse = await _fetch(thinRdap)
|
|
37
39
|
.then((r) => r.json())
|
|
@@ -194,6 +196,8 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
|
|
|
194
196
|
...((thickResponse === null || thickResponse === void 0 ? void 0 : thickResponse.events) || []),
|
|
195
197
|
...((thinResponse === null || thinResponse === void 0 ? void 0 : thinResponse.events) || []),
|
|
196
198
|
]);
|
|
199
|
+
if (type === 'ip')
|
|
200
|
+
parseIpResponse(domain, thinResponse, response);
|
|
197
201
|
return response;
|
|
198
202
|
}
|
|
199
203
|
function findStatus(statuses, domain) {
|
package/dist/ip.d.ts
ADDED
package/dist/ip.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function parseIpResponse(ip, rdap, response) {
|
|
2
|
+
var _a, _b, _c;
|
|
3
|
+
response.found = Boolean(rdap.handle);
|
|
4
|
+
const registry = rdap.port43 ? rdap.port43.match(/\.(\w+)\./)[1].toUpperCase() : '';
|
|
5
|
+
const realRdapServer = (_c = (_b = (_a = rdap.links) === null || _a === void 0 ? void 0 : _a.find(({ rel }) => rel === 'self')) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.replace(/\/ip\/.*/, '/ip/');
|
|
6
|
+
response.server = realRdapServer || 'https://rdap.org/ip/';
|
|
7
|
+
response.identity = {
|
|
8
|
+
handle: rdap.handle,
|
|
9
|
+
ipRange: {
|
|
10
|
+
start: rdap.startAddress,
|
|
11
|
+
endAddress: rdap.endAddress
|
|
12
|
+
},
|
|
13
|
+
cidr: (rdap.cidr0_cidrs || []).map((cidr) => cidr.v4prefix + '/' + cidr.length),
|
|
14
|
+
name: rdap.name,
|
|
15
|
+
type: rdap.type,
|
|
16
|
+
parent: rdap.parentHandle,
|
|
17
|
+
ip,
|
|
18
|
+
};
|
|
19
|
+
response.registrar = {
|
|
20
|
+
id: 0,
|
|
21
|
+
name: registry,
|
|
22
|
+
};
|
|
23
|
+
}
|
package/dist/utils/tldToRdap.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParseResultType, parseDomain } from "parse-domain";
|
|
2
|
-
|
|
2
|
+
let tldCache = new Map([]);
|
|
3
3
|
const tldCachePresets = [
|
|
4
4
|
["it.com", null],
|
|
5
5
|
["br.com", "https://rdap.centralnic.com/br.com"],
|
|
@@ -27,16 +27,18 @@ const tldCachePresets = [
|
|
|
27
27
|
];
|
|
28
28
|
export async function tldToRdap(domain) {
|
|
29
29
|
if (tldCache.size === 0) {
|
|
30
|
+
const tmpCache = new Map([]);
|
|
30
31
|
for (const [tld, url] of tldCachePresets) {
|
|
31
|
-
|
|
32
|
+
tmpCache.set(tld, url);
|
|
32
33
|
}
|
|
33
34
|
// console.warn(`fetching tld-to-rdap`);
|
|
34
35
|
const response = await fetch(`https://data.iana.org/rdap/dns.json`).then((r) => r.json());
|
|
35
36
|
for (const [tlds, urls] of response.services) {
|
|
36
37
|
for (const tld of tlds) {
|
|
37
|
-
|
|
38
|
+
tmpCache.set(tld, urls[0].replace(/\/$/, ""));
|
|
38
39
|
}
|
|
39
40
|
}
|
|
41
|
+
tldCache = tmpCache;
|
|
40
42
|
}
|
|
41
43
|
const parsed = parseDomain(domain);
|
|
42
44
|
if (parsed.type === ParseResultType.Listed) {
|
|
@@ -58,5 +60,8 @@ export async function tldToRdap(domain) {
|
|
|
58
60
|
// }
|
|
59
61
|
// }
|
|
60
62
|
}
|
|
63
|
+
else if (parsed.type === ParseResultType.Ip) {
|
|
64
|
+
return [domain, "https://rdap.org"];
|
|
65
|
+
}
|
|
61
66
|
return [domain, null];
|
|
62
67
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WhoisOptions, WhoisResponse, WhoisTimestampFields } from "../whois.js";
|
|
2
|
+
import { parseIpResponse } from "./ip.js";
|
|
2
3
|
import { determinePort43Domain, port43 } from "./port43.js";
|
|
3
4
|
import { findInObject } from "./utils/findInObject.js";
|
|
4
5
|
import { fixArrays } from "./utils/fixArrays.js";
|
|
@@ -41,7 +42,9 @@ export async function whois(
|
|
|
41
42
|
url = "https://rdap.org";
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
const
|
|
45
|
+
const type = domain.match(/[^\d.]/) ? "domain" : "ip";
|
|
46
|
+
|
|
47
|
+
const thinRdap = `${url}/${type}/${domain}`;
|
|
45
48
|
// console.log(`fetching thin RDAP: ${thinRdap}`);
|
|
46
49
|
|
|
47
50
|
let thinResponse = await _fetch(thinRdap)
|
|
@@ -308,6 +311,8 @@ export async function whois(
|
|
|
308
311
|
...(thinResponse?.events || []),
|
|
309
312
|
]);
|
|
310
313
|
|
|
314
|
+
if (type === 'ip') parseIpResponse(domain, thinResponse, response);
|
|
315
|
+
|
|
311
316
|
return response;
|
|
312
317
|
}
|
|
313
318
|
|
package/src/ip.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WhoisResponse } from "../whois.js";
|
|
2
|
+
|
|
3
|
+
export function parseIpResponse(ip: string, rdap: any, response: WhoisResponse) {
|
|
4
|
+
response.found = Boolean(rdap.handle);
|
|
5
|
+
|
|
6
|
+
const registry = rdap.port43 ? rdap.port43.match(/\.(\w+)\./)[1].toUpperCase() : '';
|
|
7
|
+
const realRdapServer = rdap.links?.find(({ rel }: { rel: string }) => rel === 'self')?.value?.replace(/\/ip\/.*/, '/ip/');
|
|
8
|
+
|
|
9
|
+
response.server = realRdapServer || 'https://rdap.org/ip/';
|
|
10
|
+
|
|
11
|
+
response.identity = {
|
|
12
|
+
handle: rdap.handle,
|
|
13
|
+
ipRange: {
|
|
14
|
+
start: rdap.startAddress,
|
|
15
|
+
endAddress: rdap.endAddress
|
|
16
|
+
},
|
|
17
|
+
cidr: (rdap.cidr0_cidrs || []).map((cidr: any) => cidr.v4prefix + '/' + cidr.length),
|
|
18
|
+
name: rdap.name,
|
|
19
|
+
type: rdap.type,
|
|
20
|
+
parent: rdap.parentHandle,
|
|
21
|
+
ip,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
response.registrar = {
|
|
25
|
+
id: 0,
|
|
26
|
+
name: registry,
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/utils/tldToRdap.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParseResultType, parseDomain } from "parse-domain";
|
|
2
2
|
|
|
3
3
|
type TldToRdap = [string[], string[]];
|
|
4
|
-
|
|
4
|
+
let tldCache = new Map<string, string | null>([]);
|
|
5
5
|
const tldCachePresets: [string, string | null][] = [
|
|
6
6
|
["it.com", null],
|
|
7
7
|
["br.com", "https://rdap.centralnic.com/br.com"],
|
|
@@ -32,8 +32,9 @@ export async function tldToRdap(
|
|
|
32
32
|
domain: string
|
|
33
33
|
): Promise<[string, string | null]> {
|
|
34
34
|
if (tldCache.size === 0) {
|
|
35
|
+
const tmpCache = new Map<string, string | null>([]);
|
|
35
36
|
for (const [tld, url] of tldCachePresets) {
|
|
36
|
-
|
|
37
|
+
tmpCache.set(tld, url);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
// console.warn(`fetching tld-to-rdap`);
|
|
@@ -43,9 +44,10 @@ export async function tldToRdap(
|
|
|
43
44
|
|
|
44
45
|
for (const [tlds, urls] of response.services) {
|
|
45
46
|
for (const tld of tlds) {
|
|
46
|
-
|
|
47
|
+
tmpCache.set(tld, urls[0].replace(/\/$/, ""));
|
|
47
48
|
}
|
|
48
49
|
}
|
|
50
|
+
tldCache = tmpCache;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
const parsed = parseDomain(domain);
|
|
@@ -71,6 +73,9 @@ export async function tldToRdap(
|
|
|
71
73
|
// }
|
|
72
74
|
// }
|
|
73
75
|
}
|
|
76
|
+
else if (parsed.type === ParseResultType.Ip) {
|
|
77
|
+
return [domain, "https://rdap.org"];
|
|
78
|
+
}
|
|
74
79
|
|
|
75
80
|
return [domain, null];
|
|
76
81
|
}
|
package/whois.d.ts
CHANGED
|
@@ -21,4 +21,16 @@ export type WhoisResponse = {
|
|
|
21
21
|
updated: Date | null;
|
|
22
22
|
expires: Date | null;
|
|
23
23
|
};
|
|
24
|
+
identity?: {
|
|
25
|
+
handle: string;
|
|
26
|
+
ipRange: {
|
|
27
|
+
start: string;
|
|
28
|
+
endAddress: string;
|
|
29
|
+
};
|
|
30
|
+
cidr: string[];
|
|
31
|
+
name: string;
|
|
32
|
+
type: string;
|
|
33
|
+
parent: string | null;
|
|
34
|
+
ip: string;
|
|
35
|
+
}
|
|
24
36
|
};
|