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
f75edbcc48
commit
28e7c58fde
@ -1,15 +1,15 @@
|
|||||||
// JavaScript
|
|
||||||
function fetchIPDetails(ip) {
|
function fetchIPDetails(ip) {
|
||||||
const url = `http://ip-api.com/json/${ip}`;
|
const url = `https://ipapi.co/${ip}/json`;
|
||||||
|
|
||||||
return fetch(url)
|
return fetch(url)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
return {
|
return {
|
||||||
ip: data.query,
|
ip: data.ip,
|
||||||
isp: data.as,
|
asn: data.asn,
|
||||||
countryCode: data.countryCode,
|
countryCode: data.country_code,
|
||||||
city: data.city,
|
city: data.city,
|
||||||
|
org: data.org,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -21,14 +21,13 @@ function fetchIPDetails(ip) {
|
|||||||
function updateDetailsOnPage(ipDetails) {
|
function updateDetailsOnPage(ipDetails) {
|
||||||
if (ipDetails) {
|
if (ipDetails) {
|
||||||
const ipElement = document.getElementById("ip");
|
const ipElement = document.getElementById("ip");
|
||||||
ipElement.textContent = `IP: ${ipDetails.ip}, ISP: ${ipDetails.isp}`;
|
ipElement.textContent = `IP: ${ipDetails.ip}, ASN: ${ipDetails.asn}`;
|
||||||
|
|
||||||
const countryElement = document.getElementById("country");
|
const countryElement = document.getElementById("country");
|
||||||
countryElement.textContent = `Country Code: ${ipDetails.countryCode}, City: ${ipDetails.city}`;
|
countryElement.textContent = `Country Code: ${ipDetails.countryCode}, City: ${ipDetails.city}, Org: ${ipDetails.org}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция для получения IP пользователя
|
|
||||||
function getIPAddress() {
|
function getIPAddress() {
|
||||||
fetch("https://api.ipify.org?format=json")
|
fetch("https://api.ipify.org?format=json")
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
@ -43,5 +42,4 @@ function getIPAddress() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Вызываем функцию для получения IP и данных по IP
|
|
||||||
getIPAddress();
|
getIPAddress();
|
Loading…
Reference in New Issue
Block a user