WebRTC IP Tracker

alerts whenever a WebRTC connection is made and shows its info in the js console

  1. // ==UserScript==
  2. // @name WebRTC IP Tracker
  3. // @namespace https://shitchell.com/
  4. // @version 0.2
  5. // @description alerts whenever a WebRTC connection is made and shows its info in the js console
  6. // @author Shaun Mitchel <shaun@shitchell.com>
  7. // @license wtfpl
  8. // @match *
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. var hasAlerted = false;
  13.  
  14. window.oRTCPeerConnection =
  15. window.oRTCPeerConnection || window.RTCPeerConnection;
  16.  
  17. window.RTCPeerConnection = function (...args) {
  18. const pc = new window.oRTCPeerConnection(...args);
  19.  
  20. pc.oaddIceCandidate = pc.addIceCandidate;
  21.  
  22. pc.addIceCandidate = function (iceCandidate, ...rest) {
  23. const fields = iceCandidate.candidate.split(" ");
  24.  
  25. console.log(iceCandidate.candidate);
  26. const ip = fields[4];
  27. if (fields[7] === "srflx") {
  28. getLocation(ip);
  29. }
  30. return pc.oaddIceCandidate(iceCandidate, ...rest);
  31. };
  32. return pc;
  33. };
  34.  
  35. let getLocation = async (ip) => {
  36. let url = `https://ipwhois.app/json/${ip}`;
  37. console.log("...fetching", url);
  38.  
  39. await fetch(url, {referrer: ""}).then((response) =>
  40. response.json().then((json) => {
  41. let header = `- ${ip} `.padEnd(20, "-");
  42. let localTime = (new Date()).toLocaleString([], {timeZone: json.timezone})
  43. let output = `
  44. ${header}
  45. Country: ${json.country}
  46. Region: ${json.region}
  47. City: ${json.city}
  48. Coords: (${json.latitude}, ${json.longitude})
  49. Timezone: ${json.timezone} (${json.timezone_gmt})
  50. Time: ${localTime}
  51. ISP: ${json.isp}
  52. --------------------
  53. `
  54. console.log(output);
  55. if (!hasAlerted) {
  56. alert(`[WebRTC:${ip}] see console for details`);
  57. hasAlerted = true;
  58. }
  59. })
  60. );
  61. }