Home > Backend Development > PHP Tutorial > PHP script to query the source of IP address_PHP tutorial

PHP script to query the source of IP address_PHP tutorial

WBOY
Release: 2016-07-13 10:31:52
Original
1176 people have browsed it

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/760054.htmlTechArticle? ('Content-Type:text/html;charset=utf-8' ( ['sub' = [ 'ip' = '' , (! = 'Please fill in at least one ip!' = ( ,'.' = ( ( != 3 || == || == -1 = 'Invalid ip address, please re-enter!' ' = ('h...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template