Advertisement
SqiK

ome.tv

Apr 13th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // --------------------------------------------
  2.  
  3. // PLEASE REPLACE "your-api-key-here" WITH AN
  4.  
  5. // API KEY FROM https://ipgeolocation.io/
  6.  
  7. let apiKey = "your-api-key-here";
  8.  
  9.  
  10.  
  11. window.oRTCPeerConnection =
  12.  
  13. window.oRTCPeerConnection || window.RTCPeerConnection;
  14.  
  15.  
  16.  
  17. window.RTCPeerConnection = function (...args) {
  18.  
  19. const pc = new window.oRTCPeerConnection(...args);
  20.  
  21.  
  22.  
  23. pc.oaddIceCandidate = pc.addIceCandidate;
  24.  
  25.  
  26.  
  27. pc.addIceCandidate = function (iceCandidate, ...rest) {
  28.  
  29. const fields = iceCandidate.candidate.split(" ");
  30.  
  31.  
  32.  
  33. console.log(iceCandidate.candidate);
  34.  
  35. const ip = fields[4];
  36.  
  37. if (fields[7] === "srflx") {
  38.  
  39. getLocation(ip);
  40.  
  41. }
  42.  
  43. return pc.oaddIceCandidate(iceCandidate, ...rest);
  44.  
  45. };
  46.  
  47. return pc;
  48.  
  49. };
  50.  
  51.  
  52.  
  53. let getLocation = async (ip) => {
  54.  
  55. let url = `https://api.ipgeolocation.io/ipgeo?apiKey=${apiKey}&ip=${ip}`;
  56.  
  57.  
  58.  
  59. await fetch(url).then((response) =>
  60.  
  61. response.json().then((json) => {
  62.  
  63. const output = `
  64.  
  65. ---------------------
  66.  
  67. Country: ${json.country_name}
  68.  
  69. State: ${json.state_prov}
  70.  
  71. City: ${json.city}
  72.  
  73. District: ${json.district}
  74.  
  75. Lat / Long: (${json.latitude}, ${json.longitude})
  76.  
  77. ---------------------
  78.  
  79. `;
  80.  
  81. console.log(output);
  82.  
  83. })
  84.  
  85. );
  86.  
  87. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement