admin管理员组文章数量:1316363
- 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
}
- 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
}
Share
Improve this question
asked Jul 30, 2020 at 19:26
speed7861speed7861
211 gold badge1 silver badge2 bronze badges
3 Answers
Reset to default 2This 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.
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./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./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)
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;
}
本文标签: javascriptHow to get geo data as a return from an ip on omegleStack Overflow
版权声明:本文标题:javascript - How to get geo data as a return from an ip on omegle? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742003235a2411440.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论