2
  1. Whenever I open a new Omegle video chat it returns me their IP when I run the code from the chrome console I was wondering how I can connect an API that automatically returns me the geo data along with the IP so I don't have to individually look it up.
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(' ')

if (fields[7] === 'srflx') {
console.log('IP Address:', fields[4])
}
return pc.oaddIceCandidate(iceCandidate, ...rest)

}

return pc
}
speed7861
  • 21
  • 1
  • 1
  • 2

3 Answers3

2

This is probably what you are looking for:

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(' ')

        if (fields[7] === 'srflx') {
            console.log('IP Address:', fields[4]);
            var xmlHttp = new XMLHttpRequest();
            xmlHttp.onreadystatechange = function() { 
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
                    console.log(xmlHttp.responseText);
            }
            xmlHttp.open("GET", "https://ipinfo.io/" + fields[4] + "/json" , true); // true for asynchronous
            xmlHttp.send(null);
        }

        return pc.oaddIceCandidate(iceCandidate, ...rest)
    }

    return pc
}

I included a GET for a JSON result that uses the field[4] IP from the script of the question. Works like a charm for me.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Geronimo
  • 21
  • 2
1

Try this API it returns a lot of geographic info about any IP, all you need to do is to give it the IP

http://extreme-ip-lookup.com/json/1.3.3.7

Just do a get request to this link and change 1.3.3.7 to any IP.

You can do a get request as following:

url = "http://extreme-ip-lookup.com/json/" + fields[4]
function httpGet(Url)
{
   var xmlHttp = new XMLHttpRequest();
   xmlHttp.open( "GET", Url, false ); // false for synchronous request
   xmlHttp.send( null );
   return xmlHttp.responseText;
}
geographic_info = httpGet(url)
console.log(geographic_info)
Ahmed Khaled
  • 308
  • 3
  • 14
  • can you give me an example of how i would add it to my script cuz thats what im having trouble getting it to work – speed7861 Jul 30 '20 at 20:51
  • I am not that much into JS so all I can help you is that you need to do a get request with the URL I gave you and replace the IP "1.3.3.7" with **field[4]** and then do console.log for the response that you will get – Ahmed Khaled Jul 31 '20 at 01:48
0

Create a free account at https://ipinfo.io. You get 50,000 free requests per month. Then just parse the json like so:

const request = async () => {
  const response = await fetch('https://ipinfo.io/' + StrangerIpGoesHere + '? 
token=yourIpinfoTokenGoesHere');
  const data = await response.json();
  var strangerCity = data.city;
  var strangerState = data.region;
  var strangerCountry = data.country;
}