Last active
February 19, 2022 13:19
-
-
Save Wiz-Amit/9432cfca877953a91a7481dd4d0428e5 to your computer and use it in GitHub Desktop.
Fetch Whois records using RDAP in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
whois("example.com").then((response) => console.log(response)); | |
async function fetchEndpoint(extension) { | |
let endpoint; | |
try { | |
let response = await fetch("https://data.iana.org/rdap/dns.json"); | |
let data = await response.json(); | |
let services = data["services"]; | |
let service = services.find((s) => s[0].includes(extension)); | |
endpoint = service[1][0]; | |
} catch (e) { } | |
return endpoint; | |
} | |
async function whois(domain) { | |
let extension = domain.split(".").pop(); | |
// console.log(`Fetching whois of ${domain} (extension: ${extension})`); | |
let endpoint = await fetchEndpoint(extension); | |
let response = await fetch(`${endpoint}domain/${domain}`); | |
let data = await response.json(); | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment