DNS Lookup in Client-Side Javascript
Performing a DNS lookup from the client's computer using client-side Javascript presents a challenge, as Javascript lacks direct access to the DNS service.
Edit: JSONP Webservice Solution
An updated solution emerged from the community: a JSONP webservice hosted on Google App Engine. This webservice returns the client's IP address. To use it:
function getip(json){ alert(json.ip); // alerts the ip address } <script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"> </script>
This method eliminates the need for server proxies.
Original Answer
Prior to the JSONP solution, pure Javascript could not perform DNS lookups. However, a workaround involving a server script under the same domain was suggested. By sending an XMLHttpRequest to read the output of this server script, the IP address could be obtained.
The above is the detailed content of How Can I Perform a DNS Lookup in Client-Side Javascript?. For more information, please follow other related articles on the PHP Chinese website!