Skip to content

Instantly share code, notes, and snippets.

@shitchell
Last active December 31, 2021 01:53
Show Gist options
  • Save shitchell/8ef063f8730f2b4178126cda7463e42a to your computer and use it in GitHub Desktop.
Save shitchell/8ef063f8730f2b4178126cda7463e42a to your computer and use it in GitHub Desktop.
// Userscript Extension: https://greasyfork.org/en/scripts/435913-webrtc-ip-tracker
//
// Steps:
// 1. Copy the below code
// 2. Go to https://www.omegle.com/
// 3. Open the javascript console while on omegle.com
// Windows: shift+ctrl+j
// Mac: shift+cmd+j
// 4. Paste the below code and hit enter
// 5. Navigate to the video chat page
// 6. ???
// 7. Profit
//
// NOTES:
// * You MUST open the js console from omegle.com. The js console only works
// for the page it was opened from.
// * If you enter the code while currently in a video chat, it won't show the
// IP info for that person. It only shows IP info for new connections, i.e.
// the next person you connect to.
//
// START COPYING FROM HERE...
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);
})
);
}
// ...TO HERE

WebRTC IP Tracker

A simple bit of javascript that shows the IP address of any WebRTC connection (a direct connection between you and another person's computer).

Instructions

  1. Copy the javascript code
  2. Go to https://www.omegle.com/
  3. Open the javascript console
    Windows: shift+ctrl+j
    Mac: shift+cmd+j
  4. Paste the below code and hit enter
  5. Navigate to the video chat page
  6. ???
  7. Profit

note you have to open the js console from omegle.com. the js console will only work for the page it was opened on

FAQ

Can I use this on other websites?

This will work on any website that creates a WebRTC connection (a direct connection between your computer and someone else's). Unfortunately, most websites do not implement this, so it won't work on most websites.

That said, you can install the Userscript extension which will alert you (only once per page) any time you're on a website that uses WebRTC and someone's IP information is available.

Can this be modified to work on other websites?

No. You only get the IP addresses of a device you connect to. That's why you can get the other person's IP address with this script--you're connecting directly to their deivce. Since, on most communication websites, the only device you connect to is the website's server, that's the only IP address you get--the website's IP address. To get other users' IP addresses on those websites would require hacking the website. Neither this script nor I will help you with that :P

Don't I need an API key?

No. This version uses ipwhois.io which requires no API key as long as you make 10,000 requests per month or fewer.

Soap Box

While I have your attention, I just want to point out two things:

  1. This is not a security concern. The only thing you can do with someone's IP address is get a rough location that can be upwards of 200 miles/kilometers off. You can get their ISP. And that's basically it. And yes, while this information can be enough to freak some people out, it's not enough to actually do any harm.
  2. WebRTC is actually safer than the standard. Yes, with a peer-to-peer connection everyone gets each other's IP addresses. But again, that's not a concern. The benefit is that this direct connection means the website you're on can't snoop on your data. It goes directly from you to the other person. On most websites, you send your audio/video/text data to the website, and then the website forwards it to the other person. This means they get all of your data (and the other person's). With WebRTC, your data is between you and the other person only.

Misc

Want this to load automatically on any page with a WebRTC connection? Install it as a userscript here. Requires having TamperMonkey installed first. If any website creates a WebRTC connection in the background, an alert will popup letting you know to check the JS console for the details (it will never create more than 1 alert per page).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment