-
Notifications
You must be signed in to change notification settings - Fork 15
/
ip.php
31 lines (31 loc) · 1.37 KB
/
ip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
function curl($url,$data=null){
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36','Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','Referer: http://www.ipip.net/'));
if($data){
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl,CURLOPT_POST,1);
}
$result=curl_exec($curl);
curl_close($curl);
return $result;
}
function getSubstr($str, $leftStr, $rightStr)
{
$left = strpos($str, $leftStr);
$right = strpos($str, $rightStr,$left);
if($left < 0 or $right < $left) return '';
return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr));
}
$data = curl('http://api.map.baidu.com/highacciploc/v1?qterm=mb&ak=&coord=bd09ll&extensions=3&qcip='.$_GET['ip']);
$data = json_decode($data,true);
$ip = $data['content']['formatted_address'].' '.$data['content']['location_description'];
if($ip = ' '){
$data = curl('http://www.ipip.net/ip.html','ip='.$_GET['ip']);
$ip = getSubstr($data,'<span id="myself">','</span>');
}
echo $ip;