Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
121 lines (119 loc) · 4.75 KB
/
Copy pathindex.html
File metadata and controls
121 lines (119 loc) · 4.75 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
<link href="https://fonts.googleapis.com/css?family=Rubik" rel="stylesheet">
<link rel="stylesheet" href="styles.css" type="text/css">
<link href="styles-mobile.css" rel="stylesheet"
media="screen and (max-device-width: 600px)">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
function findIP(){
const apiKey = "at_ZsQkxUILe80D3yhJt9AKMwUzlGRYN"; // should be kept in a non-public file
let re = /(?:\d{1,3}\.){3}\d{1,3}/g;
let ip = document.getElementById("input-location"); // hardcoding
if(!re.test(ip.value))
getip();
else {
let url = `https://geo.ipify.org/api/v1?apiKey=at_ZsQkxUILe80D3yhJt9AKMwUzlGRYN&ipAddress=${ip.value}`;
fetch(url,{apiKey: apiKey, ipAddress: ip.value}).then(response => response.json())
.then(data => {
// console.log(data);
$("#h3-ipaddress").html(data.ip.length === 0 ? "Unknown IP" : data.ip);
$("#h3-location").html(`${data.location.city.length === 0 ? 'Unknown location' : data.location.city+', '+ data.location.country}`);
$("#h3-timezone").html(`${data.location.timezone.length === 0 ? "Unknown timezone" : 'UTC '+data.location.timezone}`);
$("#h3-isp").html(data.isp);
drawMap([data.location.lat,data.location.lng]);
});
}
}
function getip() {
var url = $('#input-location').val();
var getLocation = function(href) {
var l = document.createElement("a");
l.href = href;
return l;
};
//var l = getLocation(url);
//var url = l.hostname;
$.ajax({
type: "GET",
url: "getip",
data: { url: getLocation(url).hostname },
contentType: "application/json; charset=utf-8",
success: function(results){
$('#ipv4_address').val(results);
},
error: function(){
}
});
}
</script>
<title>Frontend Mentor | IP Address Tracker</title>
</head>
<body>
<div class="top-section">
<h1 id="banner-text">IP Address Tracker</h1>
<form id="form-ip" name="form-ip" onsubmit="findIP();return false">
<div class="top-section-container">
<input id="input-location" placeholder="Search for any IP address or domain" autocomplete="off">
<button id="button-enter-location" onclick="findIP()" type="submit">
</div>
</form>
</div>
<div class="bottom-section">
<div class="infobox-container">
<div id="ipaddress-infobox" class="infobox">
<p>IP Address</p>
<h3 id="h3-ipaddress"></h3>
</div>
<div class="infobox-divider"></div>
<div id="location-infobox" class="infobox">
<p>Location</p>
<h3 id="h3-location"></h3>
</div>
<div class="infobox-divider"></div>
<div id="timezone-infobox" class="infobox">
<p>Timezone</p>
<h3 id="h3-timezone"></h3>
</div>
<div class="infobox-divider"></div>
<div id="isp-infobox" class="infobox">
<p>ISP</p>
<h3 id="h3-isp"></h3>
</div>
</div>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid');
function drawMap(locationVar){
// console.log("locationvar: ", locationVar)
// if(locationVar.length === 0)
// // mymap.setView([51.505, -0.09], 13);
// else
mymap.setView(locationVar, 13);
var customMarkerIcon = L.icon({
iconUrl: 'images/icon-location.svg',
// iconSize: [38, 95],
iconAnchor: [0, 0],
popupAnchor: [25, -10],});
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'mapbox/streets-v11',
tileSize: 512,
zoomOffset: -1
}).addTo(mymap);
L.marker(locationVar, {icon: customMarkerIcon}).addTo(mymap);
}
</script>
</div>
</div>
</body>
</html>