-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipinfo.html
84 lines (76 loc) · 2.75 KB
/
ipinfo.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>IP Info</title>
<meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Google+Sans:400,500,700|Google+Sans+Text:400&lang=en">
<style>
#info {
position: absolute;
top: 0;
right: 0;
margin: 10px;
padding: 9px 11px;
width: 279.5px;
background-color: white;
border-radius: 2px;
box-shadow: rgb(0 0 0 / 30%) 0px 1px 4px -1px;
user-select: text;
font-family: Roboto, Arial;
}
#ip {
color: black;
font-size: 14px;
height: 16px;
font-weight: 500;
}
#org {
color: #5b5b5b;
font-size: 12px;
margin-top: 6px;
}
#details {
text-decoration: none;
color: #1a73e8;
font-size: 12px;
}
</style>
</head>
<body style="margin: 0; overflow: hidden;">
<iframe id="map"
frameborder="0" scrolling="no"
style="width: 100vw; height: 100vh;"/>
</iframe>
<div id="info" style="display: none;">
<div id="ip"></div>
<div id="org"></div>
<div style="margin-top: 19px;">
<a id="details" href="#" target="_blank" aria-label="View details">View details</a>
</div>
</div>
<script>
async function updateInfo() {
// const ipInfoProvider = 'https://ipinfo.io';
// const ipInfoProviderUrl = 'https://ipapi.co';
const ipInfoProviderUrl = 'https://api.ipbase.com/v2/info';
const ipInfo = await fetch(ipInfoProviderUrl).then(res => res.json())
.then(body => body.data);
console.info('ipInfo:', ipInfo);
const infoElement = document.getElementById('info');
const ipElement = document.getElementById('ip');
ipElement.innerText = ipInfo.ip;
const orgElement = document.getElementById('org');
orgElement.innerText = ipInfo.connection.organization;
const detailsElement = document.getElementById('details');
detailsElement.href = ipInfoProviderUrl;
const mapIframe = document.getElementById('map');
const mapQuery = `${ipInfo.location.latitude},${ipInfo.location.longitude}`;
mapIframe.src = `https://maps.google.com/maps?q=${mapQuery}&z=10&output=embed`;
mapIframe.onload = () => { infoElement.style.display = '';}
};
updateInfo()
window.addEventListener('online', updateInfo);
</script>
</body>
</html>