-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-domain-availability.html
More file actions
73 lines (63 loc) · 2.57 KB
/
check-domain-availability.html
File metadata and controls
73 lines (63 loc) · 2.57 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Domain Availability Checker by Toolzr</title>
<meta name="description" content="Check if a domain name is available across popular TLDs using RDAP and DNS resolution.">
</head>
<body>
<h1>Domain Availability Checker</h1>
<input type="text" id="domainInput" placeholder="Enter domain name">
<button id="checkButton">Check Availability</button>
<h2>Results:</h2>
<pre id="results"></pre>
<p>This tool is brought to you by <a href="https://toolzr.com" target="_blank">Toolzr</a> and is open source, licensed under the <a href="https://opensource.org/licenses/MIT" target="_blank">MIT License</a>. The online version can be found at <a href="https://toolzr.com/domain-availability" target="_blank">toolzr.com/domain-availability</a>.</p>
<script>
const tlds = [".com", ".net", ".org", ".io", ".cc", ".me", ".info", ".top", ".online", ".xyz"];
async function domainResolves(domain) {
try {
const response = await fetch(`https://dns.google/resolve?name=${domain}&type=A`);
const data = await response.json();
return data.Answer !== undefined;
} catch (error) {
return false;
}
}
async function checkDomain(domain) {
const url = `https://rdap.org/domain/${domain}`;
try {
const response = await fetch(url);
if (!response.ok) {
if (response.status === 404) {
return !(await domainResolves(domain));
}
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return !data.events;
} catch (error) {
return false;
}
}
document.getElementById('checkButton').addEventListener('click', async function() {
const input = document.getElementById("domainInput").value.trim();
const resultsDiv = document.getElementById("results");
resultsDiv.innerHTML = "";
if (!input) {
resultsDiv.innerHTML = "<p style='color:red;'>Please enter a domain name.</p>";
return;
}
const hasTld = input.includes(".");
const domainsToCheck = hasTld ? [input] : tlds.map(tld => `${input}${tld}`);
for (const domain of domainsToCheck) {
const isAvailable = await checkDomain(domain);
const resultP = document.createElement("p");
resultP.style.color = isAvailable ? "green" : "red";
resultP.textContent = `${domain}: ${isAvailable ? "Available ✅" : "Taken ❌"}`;
resultsDiv.appendChild(resultP);
}
});
</script>
</body>
</html>