经营一个网站,作为站长最关心的可能就是搜索引擎蜘蛛今天来了吗,蜘蛛来爬了几次等等,查看日志的时候可能会看到很多ip或很多带蜘蛛标识spider、bot等访客,打眼一看并不知是否是真蜘蛛,那么如何检测ip为真假蜘蛛呢,一般我们都会去搜索下网上公布的一些真蜘蛛的ip地址,拿着ip去搜索一下看看,这样是很麻烦的;想要省事可以试试使用,蓝叶分享php检测ip是否为真蜘蛛的方法,真假蜘蛛识别php代码。
蓝叶分享php检测ip是否为真蜘蛛的代码,复制代码到php文件中,然后通过浏览器访问http://youdomain/ip.php?ip=ip地址,查询到的结果中,一眼看去就知蜘蛛的真假,例如查询220.181.108.208这个ip,返回结果是{"statu":1,"domain":"baiduspider-220-181-108-208.crawl.baidu.com"},这么一看就知道是真蜘蛛无疑了。
<?php /* * 检测IP是否为蜘蛛 * author:蓝叶 * url:lanye.org */ error_reporting(0); header('Content-type: application/json;charset=utf-8'); $ip = isset($_GET['ip']) ? addslashes($_GET['ip']) : '220.181.108.208'; $url = 'https://mxtoolbox.com/api/v1/Lookup?command=ptr&argument='.$ip.'&resultIndex=2&disableRhsbl=true&format=2'; $dat = Curl($url); if(preg_match('/"HTML_Value"/i', $dat)){ $json = json_decode($dat,1); $html = $json['HTML_Value']; preg_match('/<td.*?class=(\'|")table-column-Domain_Name(\'|")><a.*?>(.*?)<\/a><\/td>[\s\S]*?<td class=(\'|")table-column-TTL(\'|")>/i', $html, $match); if($match){ $json = json_encode(array('statu'=>1,'domain'=>$match[3])); }else{ $json = json_encode(array('statu'=>0,'domain'=>'')); } }else{ $json = json_encode(array('statu'=>0,'domain'=>'')); } echo $json; function Curl($url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, array('cookie: _vwo_uuid_v2=D67F0D6FB6FCBC2CA6F3B14F078BE3F9D|f73ff5d37c04410ff4191525eba34e12;hubspotutk=86006f1d0611dce0466876d53694e64c;__hssrc=1;_cioanonid=55ad2a31-c8e1-ca97-faee-3d722dd1001b;cebs=1;_ce.clock_event=1;_ce.clock_data=-113%2C36.5.145.106%2C1%2Cb9cbd8dc13f19f9e7eb854f472bfa274;_ce.s=v~4b6ff5f9f5749eeab6eae19bcb3e2ce73cb9a387~lcw~1686819050687~vpv~0~v11.rlc~1686819052619~lcw~1686819052619; _ga=GA1.1.161954312.1686819047;__hssc=179393531.2.1686819049218;cebsp_=2;_ga_YT4L4GZFH2=GS1.1.1686819047.1.1.1686819426.60.0.0','tempauthorization: 27eea1cd-e644-4b7b-bebe-38010f55dab3')); curl_setopt($curl, CURLOPT_REFERER, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $response = curl_exec($curl); curl_close($curl); return $response; }
免责声明:
本页网址:点击复制分享给朋友吧!
本站分享的一切内容资源如若没有备注,均为蓝叶原创,如需转载请注明出处;如有侵权请与我们联系处理。敬请谅解!