Is it possible to perform a DNS lookup (convert hostname to IP address) using Javascript on the client side?
P粉459578805
2023-08-21 22:08:37
<p>I want to use client-side Javascript to perform a DNS lookup (see a hostname to IP address mapping from the client machine). Is this possible? </p>
Edit: This question tickled me, so I built a JSONP webservice on Google App Engine that returns the client's IP address. usage:
Yeah, no server proxy required.
Pure JS cannot achieve this. If you have a server script that prints output on the same domain, you can send an XMLHttpRequest to read it.
In the JavaScript standard library, there is no concept of a host or IP address. So you need to access some external service to find the hostname.
I recommend that you host a cgi-bin that looks up the IP address of the hostname and accesses it via JavaScript.