-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeIP.html
50 lines (45 loc) · 1.84 KB
/
seeIP.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Show IP Address</title>
</head>
<body>
<h1>Your IP Address:</h1>
<p>IP6</p> <p id="ip-address">Loading...</p>
<p>IP4</p> <p id="ipv4-address">Loading...</p>
<script>
// Function to get the user's IP address
function getIPAddress() {
fetch('https://api64.ipify.org?format=json')
.then(response => response.json())
.then(data => {
// Update the HTML with the IP address
document.getElementById('ip-address').textContent = data.ip;
})
.catch(error => {
console.error('Error fetching IP address:', error);
document.getElementById('ip-address').textContent = 'Error';
});
}
// Function to get the user's IPv4 address
function getIPv4Address() {
fetch('https://ipinfo.io/json')
.then(response => response.json())
.then(data => {
// Update the HTML with the IPv4 address
document.getElementById('ipv4-address').textContent = data.ip;
})
.catch(error => {
console.error('Error fetching IPv4 address:', error);
document.getElementById('ipv4-address').textContent = 'Error';
});
}
// Call the function when the page loads
document.addEventListener('DOMContentLoaded', getIPAddress);
//call the function when the page loads
document.addEventListener('DOMContentLoaded',getIPv4Address);
</script>
</body>
</html>