Home > Web Front-end > JS Tutorial > Can I Get a Client's IP Address with JavaScript Alone?

Can I Get a Client's IP Address with JavaScript Alone?

DDD
Release: 2024-12-27 17:16:12
Original
969 people have browsed it

Can I Get a Client's IP Address with JavaScript Alone?

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:

    • Returns: Country code, region, city, latitude, longitude, ISP, and estimated connection time.
    • Usage:

      let apiKey = '1be9a6884abd4c3ea143b59ca317c6b2';
      $.getJSON('https://ipgeolocation.abstractapi.com/v1/?api_key=' + apiKey, function(data) {
      console.log(JSON.stringify(data, null, 2));
      });
      Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template