Categories
JavaScript Answers

How to perform a DNS lookup from hostname to IP address using client-side JavaScript?

Spread the love

Sometimes, we want to perform a DNS lookup from hostname to IP address using client-side JavaScript.

In this article, we’ll look at how to perform a DNS lookup from hostname to IP address using client-side JavaScript.

How to perform a DNS lookup from hostname to IP address using client-side JavaScript?

To perform a DNS lookup from hostname to IP address using client-side JavaScript, we can use a 3rd party API.

For instance, we write

const response = await fetch("https://dns.google/resolve?name=example.com");
const json = await response.json();
console.log(json);

to call fetch in an async function to make a get request to https://dns.google/resolve with the name query parameter set to the hostname we want to resolve.

Then we get the IP address from the JSON response we get from response.json.

Conclusion

To perform a DNS lookup from hostname to IP address using client-side JavaScript, we can use a 3rd party API.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.