sh 脚本识别搜索引擎蜘蛛

  1. 白名单的 shell 脚本 istrustip.sh

    basepath='/usr/local/openresty/nginx/conf/lua/sh'
    echo $1 | grep -f $basepath/trust_ips.txt | awk '{if($0) print 1}'

    trust_ips.txt

    ^42.236.101.*
    ^42.236.102.*
    ^42.236.103.*
    ^42.236.10.*
    ..
  2. 反查IP 的 shell 脚本 isspider.sh

# 反查IP 45.152.11.106.in-addr.arpa domain name pointer shenmaspider-106-11-152-45.crawl.sm.cn.
basepath='/usr/local/openresty/nginx/conf/lua/sh'

hostname=`host $1 | grep -f $basepath/spider.txt | awk '{print $5}'`
if [ ! -z $hostname ];
then
    # 反查域名 shenmaspider-106-11-152-45.crawl.sm.cn has address 106.11.152.45
    hostip=`host $hostname | awk '{print $4}'`

    if [ "$hostip" = "$1" ];
    then
        echo 1
        exit
    fi
fi

echo 0

spider.txt

sm.cn
baidu.com
baidu.jp
sogou.com
bytedance.com
msn.com
googlebot.com
本作品采用《CC 协议》,转载必须注明作者和本文链接
welcome come back
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
95
粉丝
24
喜欢
156
收藏
348
排名:324
访问:2.9 万
私信
所有博文
社区赞助商