Savelyev_Vyacheslav

IP адрес

Jul 5th, 2024
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fetch('https://api.ipify.org?format=json')
  2.     .then(response => response.json())
  3.     .then(data => {
  4.         const ipAddress = data.ip;
  5.         console.log(`IP Address: ${ipAddress}`); // Вывод IP-адреса пользователя в консоль
  6.  
  7.         // Запрос к геолокационному сервису для получения местоположения
  8.         fetch(`https://ipinfo.io/${ipAddress}/geo`)
  9.             .then(response => response.json())
  10.             .then(location => {
  11.                 console.log(`Location: ${JSON.stringify(location)}`); // Вывод географического местоположения
  12.             });
  13.     });
  14.  
Advertisement
Add Comment
Please, Sign In to add comment