Skip to content

Commit

Permalink
Added lookup page
Browse files Browse the repository at this point in the history
  • Loading branch information
ComputerTech312 committed Apr 24, 2024
1 parent 5edd191 commit 87782b7
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<li><a href="https://github.com/computertech312">GitHub</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="https://forum.computertech.co">Forum</a></li>
<li><a href="lookup.html">Lookup</a></li>
</ul>
</nav>
</header>
Expand Down
52 changes: 52 additions & 0 deletions lookup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="This is a DNS and IP lookup page of ComputerTech.">
<title>DNS and IP Lookup</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="wrapper">
<header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="https://paste.computertech.co">Paste</a></li>
<li><a href="https://github.com/computertech312">GitHub</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="https://forum.computertech.co">Forum</a></li>
<li><a href="lookup.html">DNS & IP Lookup</a></li>
</ul>
</nav>
</header>
<main>
<h1>DNS and IP Lookup</h1>
<form id="lookup-form">
<select id="lookup-type">
<option value="ip">IP Lookup</option>
<option value="A">DNS A Record</option>
<option value="AAAA">DNS AAAA Record</option>
<option value="MX">DNS MX Record</option>
<option value="TXT">DNS TXT Record</option>
<option value="CNAME">DNS CNAME Record</option>
<option value="NS">DNS NS Record</option>
<option value="SOA">DNS SOA Record</option>
<option value="PTR">DNS PTR Record</option>
<!-- Add more options here -->
</select>
<input type="text" id="lookup-input" placeholder="Enter value">
<button type="submit">Lookup</button>
</form>
<div id="lookup-result">
<!-- Lookup result will be displayed here -->
</div>
</main>
<footer>
<p>&copy; 2024 ComputerTech</p>
</footer>
</div>
<script src="lookup.js"></script>
</body>
</html>
82 changes: 82 additions & 0 deletions lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
document.getElementById('lookup-form').addEventListener('submit', function(event) {
event.preventDefault();
const lookupType = document.getElementById('lookup-type').value;
const lookupInput = document.getElementById('lookup-input').value;
if (lookupInput) {
document.getElementById('lookup-result').textContent = 'Loading...';
if (lookupType === 'ip' && isValidIP(lookupInput)) {
ipLookup(lookupInput);
} else if (lookupType === 'ping' && (isValidIP(lookupInput) || isValidDomain(lookupInput))) {
pingService(lookupInput); // Handle ping service
} else if (isValidDomain(lookupInput)) {
dnsLookup(lookupType, lookupInput);
} else {
document.getElementById('lookup-result').textContent = 'Invalid input. Please enter a valid value.';
}
}
});

function isValidIP(ip) {
const ipV4Regex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/;
const ipV6Regex = /^([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])$/;
return ipV4Regex.test(ip) || ipV6Regex.test(ip);
}

function isValidDomain(domain) {
const domainRegex = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/;
return domainRegex.test(domain);
}

function ipLookup(ip) {
fetch(`http://ip-api.com/json/${ip}`)
.then(response => {
if (!response.ok) {
throw new Error('IP lookup failed');
}
return response.json();
})
.then(data => {
const resultDiv = document.getElementById('lookup-result');
resultDiv.innerHTML = `
<h2>IP Lookup Result</h2>
<p><strong>IP:</strong> ${data.query}</p>
<p><strong>City:</strong> ${data.city}</p>
<p><strong>Region:</strong> ${data.regionName}</p>
<p><strong>Country:</strong> ${data.country}</p>
<p><strong>ISP:</strong> ${data.isp}</p>
<iframe
width="600"
height="450"
style="border:0"
loading="lazy"
allowfullscreen
src="https://www.google.com/maps/embed/v1/place?key=AIzaSyAtrFh_crzA2RkiayqwdMLhE4kx4Op9RSI&q=${data.lat},${data.lon}">
</iframe>
`;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('lookup-result').textContent = 'IP lookup failed. Please try again.';
});
}

function dnsLookup(type, domain) {
fetch(`https://dns.google/resolve?name=${domain}&type=${type}`)
.then(response => {
if (!response.ok) {
throw new Error('DNS lookup failed');
}
return response.json();
})
.then(data => {
const resultDiv = document.getElementById('lookup-result');
resultDiv.innerHTML = `
<h2>DNS ${type} Lookup Result</h2>
${data.Answer.map(answer => `<p><strong>${answer.name}</strong> ${answer.data}</p>`).join('')}
`;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('lookup-result').textContent = 'DNS lookup failed. Please try again.';
});
}

0 comments on commit 87782b7

Please sign in to comment.