Is it possible to perform a DNS lookup (convert hostname to IP address) using Javascript on the client side?
P粉459578805
P粉459578805 2023-08-21 22:08:37
0
2
520
<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>
P粉459578805
P粉459578805

reply all(2)
P粉204136428

Edit: This question tickled me, so I built a JSONP webservice on Google App Engine that returns the client's IP address. usage:

<script type="application/javascript">
function getip(json){
  alert(json.ip); // 弹出IP地址
}
</script>

<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"> </script>

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.

P粉677573079

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template