Get the location of iP and network operator
Applications used:7
Product services support payments in USD, HKD, and USDT
HTTP protocol:
http://api.youripapi.com/ipdata/
HTTPS protocol:
https://api.youripapi.com/ipdata/
* The API interface may be blocked due to various network reasons and attacks. Please make redundancy and exception handling during development
*If the status code returned by the HTTP request is not 200, perform an exception. For example, the status code 202 May be caused by invalid Token, insufficient balance, or incorrect format
iP query interface example for Javascript:
function ajax(params){
params = params||{};
if (!params.url) {
throw new Error('Necessary parameters are missing.');
}
var random = +new Date;
var hander = null;
var options = {
url: '',
type: 'GET',
timeout: 5000,
cache: true,
async: true,
xhrFields: {},
dataType: 'json',
data: {},
jsonp: 'callback',
jsonpCallback: 'jsonp_' + random,
error: function() {},
success: function(){},
complete: function(){}
};
var formatParams = function(json) {
var arr = [];
for(var i in json) {
arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(json[i]));
}
return arr.join("&");
};
for(var i in params){
switch(i){
case 'type':
options[i] = params[i].toUpperCase();
break;
case 'dataType':
options[i] = params[i].toLowerCase();
break;
default:
options[i] = params[i];
}
}
if(typeof options.data =='object'){
options.data = formatParams(options.data);
}
if(options.dataType=='jsonp'){
options.cache = params.cache||false;
// Insert dynamic scripts and callback functions
var $head = document.getElementsByTagName('head')[0];
var $script = document.createElement('script');
$head.appendChild($script);
window[options.jsonpCallback] = function (json) {
$head.removeChild($script);
window[options.jsonpCallback] = null;
hander && clearTimeout(hander);
options.success(json);
options.complete();
};
// Sent request
if(options.cache){
options.data += options.data?'&_'+random:'_'+random;
}
options.data += '&'+options.jsonp+'='+options.jsonpCallback;
$script.src = (options.url + '?' + options.data).replace('?&','?');
// Timeout
hander = setTimeout(function(){
$head.removeChild($script);
window[options.jsonpCallback] = null;
options.error();
options.complete();
}, options.timeout);
}else{
if(options.cache){
options.data += options.data?'&_'+random:'_'+random;
}
// create xhr object
var xhr = new (self.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP");
if(!xhr){
return false;
}
// Sent request
if (options.type == 'POST') {
xhr.open(options.type, options.url, options.async);
xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
}else{
options.url += options.url.indexOf('?')>-1?'&'+options.data:'?'+options.data;
xhr.open(options.type, options.url, options.async);
options.data = null;
}
if(options.xhrFields){
for(var field in options.xhrFields){
xhr[field]= options.xhrFields[field];
}
}
xhr.send(options.data);
// timeout
var requestDone = false;
hander = setTimeout(function() {
requestDone = true;
if(xhr.readyState != 4){
xhr.abort();
options.error();
}
options.complete();
}, options.timeout);
// State
xhr.onreadystatechange = function(){
if(xhr.readyState == 4&&!requestDone) {
if(xhr.status>=200 && xhr.status<300||xhr.status == 304) {
var data = options.dataType == "xml" ? xhr.responseXML : xhr.responseText;
if (options.dataType == "json") {
try{
data = JSON.parse(data);
}catch(e){
data = eval('(' + data + ')');
}
}
options.success(data);
} else {
options.error();
}
hander && clearTimeout(hander);
options.complete();
}
};
}
}
ajax({
'url':'https://api.youripapi.com/ip/',
'data':{
'ip':'8.8.8.8',
'oid':'35553',
'mid':'2',
'token':'00d5cb1fac5dc5cbfe2ff218292a2dfd33' // It is not secure, refresh the token periodically and compress the file
},
'dataType':'jsonp',
'success':function(json){
console.log(json);
}
});
$.ajax({
'url':'https://api.youripapi.com/ip/',
'data':{
'ip':'8.8.8.8',
'oid':'35553',
'mid':'2',
'token':'00d5cb1fac5dc5cbfe2ff218292a2dfd33' // It is not secure, refresh the token periodically and compress the file
},
'dataType':'jsonp',
'success':function(json){
console.log(json);
}
});