How to Retrieve a Client's IP Address Using JavaScript
Question:
How can I obtain a client's IP address using JavaScript without utilizing server-side code?
Answer:
Leveraging a third-party script or service that returns JSON is a viable solution. Here are a few active and free IP lookup services to consider:
Abstract IP Geolocation API:
Usage:
let apiKey = '1be9a6884abd4c3ea143b59ca317c6b2'; $.getJSON('https://ipgeolocation.abstractapi.com/v1/?api_key=' + apiKey, function(data) { console.log(JSON.stringify(data, null, 2)); });
The above is the detailed content of Can I Get a Client's IP Address with JavaScript Alone?. For more information, please follow other related articles on the PHP Chinese website!