1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Get Passive DNS by IP |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | account_identifier: string, |
13 | start_end_params: string | undefined, |
14 | ipv4: string | undefined, |
15 | page: string | undefined, |
16 | per_page: string | undefined |
17 | ) { |
18 | const url = new URL( |
19 | `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/intel/dns` |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["start_end_params", start_end_params], |
23 | ["ipv4", ipv4], |
24 | ["page", page], |
25 | ["per_page", per_page], |
26 | ]) { |
27 | if (v !== undefined && v !== "") { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | "X-AUTH-EMAIL": auth.email, |
35 | "X-AUTH-KEY": auth.key, |
36 | Authorization: "Bearer " + auth.token, |
37 | }, |
38 | body: undefined, |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|