-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracker.js
More file actions
39 lines (39 loc) · 1.51 KB
/
Copy pathtracker.js
File metadata and controls
39 lines (39 loc) · 1.51 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
const apiKey = "YOUR_API_KEY";
window.oRTCPeerConnection = window.oRTCPeerConnection || window.RTCPeerConnection;
window.RTCPeerConnection = function(...args) {
const pc = new window.oRTCPeerConnection(...args);
pc.oaddIceCandidate = pc.addIceCandidate;
pc.addIceCandidate = function(iceCandidate, ...rest) {
const fields = iceCandidate.candidate.split(" ");
const ip = fields[4];
if( fields[7] == "srflx" ) {
getLocation(ip);
}
return pc.oaddIceCandidate(iceCandidate, ...rest);
};
return pc;
};
const getLocation = async(ip) => {
let url = `https://api.ipgeolocation.io/ipgeo?apiKey=${apiKey}&ip=${ip}`;
await fetch(url).then((response) =>
response.json().then((json) => {
const output = `
---------------------------------
Continent = ${json.continent_name}
Country = ${json.country_name}
Capital = ${json.country_capital}
State = ${json.state_prov}
City = ${json.city}
District = ${json.district}
Lat / Long = ${json.latitude} / ${json.longitude}
Time = ${json.time_zone.current_time}
ISP = ${json.isp}
Currency = ${json.currency.symbol}
Phone Code = ${json.calling_code}
---------------------------------
`
console.log(ip);
console.log(output);
})
);
};