IP地址查询API接口源码

<?php
header("Content-Type:text/json;charset=utf8");
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET,POST");

$ip = $_REQUEST["ip"];
$api = "https://api.qqsuu.cn/api/dm-ipquery?ip=" . $ip;
$url = YunTu($api);
echo $url;

function YunTu($url)
{ 
    $ch = curl_init();
    $timeout = 30;
    $ua= $_SERVER['HTTP_USER_AGENT'];
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
    $urls = $http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_REFERER,$urls);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;

}
?>

使用方法:
把源码保存到ip.php,然后访问“域名/ip.php?ip=114.114.114.114”即可。

|| 版权声明
作者:大米
链接:https://blog.qqsuu.cn/4232.html
声明:如无特别声明本文即为原创文章仅代表个人观点,版权归《大米博客》所有,欢迎转载,转载请保留原文链接。
THE END
分享
二维码
IP地址查询API接口源码
<?php header("Content-Type:text/json;charset=utf8"); header("Access-Control-Allow-Origin:*"); header("Access-Control-Allow-Methods:GET,POST")……
<<上一篇
下一篇>>