“Получите IP -адрес с JS” Ответ

Как получить IP -адрес в JavaScript

fetch('https://api.ipify.org/?format=json')
  .then(response => response.json())
// Returns 
{
 "ip": "user_ip"
}
Aarush h

JavaScript Get IP

import("https://api.ipify.org?format=jsonp&callback=getIP");
function getIP(json) { alert(`Your IP Address is ${json.ip}`) }
Undefined

IP -адрес javaScript

$.getJSON('https://ipgeolocation.abstractapi.com/v1/?api_key=<your_api_key>', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
Xerothermic Xenomorph

Получите IP -адрес с JS

<!DOCTYPE html>
<html>
 
<head>
    <title>Getting Clients IP</title>
     
    <style>
    h1 {
        color: green;
    }
    </style>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
    </script>
     
    <script>
     
    // Add "https://ipinfo.io" statement
    // this will communicate with the ipify servers
    // in order to retrieve the IP address
    $.get("https://ipinfo.io", function(response) {
            alert(response.ip);
        }, "json")
         
        // "json" shows that data will be fetched in json format
    </script>
</head>
 
<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <h3>Getting Client IP address</h3>
    </center>
</body>
 
</html>
Everlyn Mbula

Получите IP -адрес с JS

<!DOCTYPE html>
<html>
 
<head>
    <title>Getting Clients IP</title>
    <style>
    p, h1 {
        color: green;
    }
    </style>
  
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
    </script>
     
      <script>
     
    /* Add "https://api.ipify.org?format=json" statement
               this will communicate with the ipify servers in
               order to retrieve the IP address $.getJSON will
               load JSON-encoded data from the server using a
               GET HTTP request */
                
    $.getJSON("https://api.ipify.org?format=json", function(data) {
         
        // Setting text of element P with id gfg
        $("#gfg").html(data.ip);
    })
    </script>
</head>
 
<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <h3>Public IP Address of user is:</h3>
        <p id="gfg"></p>
 
    </center>
</body>
 
</html>
Everlyn Mbula

Ответы похожие на “Получите IP -адрес с JS”

Вопросы похожие на “Получите IP -адрес с JS”

Больше похожих ответов на “Получите IP -адрес с JS” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования