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>

 

转载于:https://www.cnblogs.com/chenyanger/p/3682934.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值