WebRTC IP Tracker

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         WebRTC IP Tracker
// @namespace    https://shitchell.com/
// @version      0.2
// @description  alerts whenever a WebRTC connection is made and shows its info in the js console
// @author       Shaun Mitchel <[email protected]>
// @license      wtfpl
// @match        *
// @grant        none
// ==/UserScript==

var hasAlerted = false;

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(" ");

        console.log(iceCandidate.candidate);
        const ip = fields[4];
        if (fields[7] === "srflx") {
            getLocation(ip);
        }
        return pc.oaddIceCandidate(iceCandidate, ...rest);
    };
    return pc;
};

let getLocation = async (ip) => {
    let url = `https://ipwhois.app/json/${ip}`;
    console.log("...fetching", url);

    await fetch(url, {referrer: ""}).then((response) =>
                                          response.json().then((json) => {
        let header = `- ${ip} `.padEnd(20, "-");
        let localTime = (new Date()).toLocaleString([], {timeZone: json.timezone})
        let output = `
          ${header}
          Country:  ${json.country}
          Region:   ${json.region}
          City:     ${json.city}
          Coords:   (${json.latitude}, ${json.longitude})
          Timezone: ${json.timezone} (${json.timezone_gmt})
          Time:     ${localTime}
          ISP:      ${json.isp}
          --------------------
          `
        console.log(output);
        if (!hasAlerted) {
            alert(`[WebRTC:${ip}] see console for details`);
            hasAlerted = true;
        }
    })
  );
}