mirror of
https://github.com/fruworg/fruworg.github.io.git
synced 2024-11-16 09:27:17 +03:00
ip
This commit is contained in:
parent
55c0d9a0c7
commit
f75edbcc48
@ -1 +1,47 @@
|
||||
// JavaScript
|
||||
function fetchIPDetails(ip) {
|
||||
const url = `http://ip-api.com/json/${ip}`;
|
||||
|
||||
return fetch(url)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
return {
|
||||
ip: data.query,
|
||||
isp: data.as,
|
||||
countryCode: data.countryCode,
|
||||
city: data.city,
|
||||
};
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching IP details:", error);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
function updateDetailsOnPage(ipDetails) {
|
||||
if (ipDetails) {
|
||||
const ipElement = document.getElementById("ip");
|
||||
ipElement.textContent = `IP: ${ipDetails.ip}, ISP: ${ipDetails.isp}`;
|
||||
|
||||
const countryElement = document.getElementById("country");
|
||||
countryElement.textContent = `Country Code: ${ipDetails.countryCode}, City: ${ipDetails.city}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Функция для получения IP пользователя
|
||||
function getIPAddress() {
|
||||
fetch("https://api.ipify.org?format=json")
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
const userIP = data.ip;
|
||||
fetchIPDetails(userIP).then((ipDetails) => {
|
||||
updateDetailsOnPage(ipDetails);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching IP:", error);
|
||||
});
|
||||
}
|
||||
|
||||
// Вызываем функцию для получения IP и данных по IP
|
||||
getIPAddress();
|
Loading…
Reference in New Issue
Block a user