Can I perform a DNS lookup (hostname to IP address) using client-side Javascript?

Edit: This question gave me an itch, so I put up a JSONP webservice on Google App Engine that returns the clients ip address. Usage:

<script type="application/javascript">
function getip(json){
  alert(json.ip); // alerts the ip address
}
</script>

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

Yay, no server proxies needed.


Pure JS can’t. If you have a server script under the same domain that prints it out you could send a XMLHttpRequest to read it.

Leave a Comment