php查询ip地址来源归属地的脚本

王朝学院·作者佚名  2016-05-25
窄屏简体版  字體: 小  |  中  |  大  |  超大  

php查询ip地址来源归属地的脚本 1 <?php 2 header('Content-Type:text/html;charset=utf-8'); 3 4 if($_GET['sub']){ 5 $ip = $_GET['ip']; 6 $msg = ''; 7 ipSearch(); 8 } 9 10 function ipSearch(){11 global $ip,$msg;12 if(!$ip){13 $msg = '请至少填写一个ip!';14 return;15 }16 $arises = substr_count($ip,'.');17 $long = ip2long($ip);18 if($arises != 3 || $long == false || $long== -1){19 $msg = '无效ip地址,请重新输入!';20 return;21 }22 $content = file_get_contents('http://www.ip138.com/ips1388.asp?action=2&ip='.$ip);23 $content = iconv('gb2312', 'utf-8', $content);24 $pos = stripos($content, '<li>本站主数据');25 if(!$pos){26 $msg = '没有查询到!';27 return;28 }29 $endPos = stripos($content, '</li>', $pos);30 $jumpLen = strlen('<li>本站主数据:');31 $address = substr($content, $pos+$jumpLen, $endPos-$pos-$jumpLen);32 $msg = $address;33 return;34 }35 36 ?><!DOCTYPE html>37 <html>38 <head>39 <meta charset="utf-8">40 <title>test</title>41 </head>42 <body>43 <form method="get">44 <input type="text" name="ip" />45 <input type="submit" value="search" name="sub" />46 </form><br />47 <?php echo $msg; ?>48 </body>49 </html>

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航