0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

コマンド一発でIPアドレスがGoogle botのIPかどうかを調べたい

Posted at
function is-googlebot-ip() {
    if [ $# -eq 0 ]; then
        echo "使用方法: is-googlebot-ip <IPアドレス> [IPアドレス2 ...]" >&2
        return 2  # 引数エラー
    fi
    local overall_status=0
    for target_ip in "$@"; do
        local domain=$(host $target_ip 2>/dev/null | grep -oE '[^ ]+\.(googlebot|google|googleusercontent)\.com\.$' | sed 's/\.$//')
        if [ -n "$domain" ] && host $domain 2>/dev/null | grep -q "has address $target_ip"; then
            echo "✅ $target_ip は正規のGooglebot IPです (Domain: $domain)"
        else
            echo "❌ $target_ip はGooglebot IPではありません"
            overall_status=1
        fi
    done
    return $overall_status
}
  • チェックしたいIPを渡して実行する
# Google bot IPの場合
is-googlebot-ip 66.249.66.1
✅ 66.249.66.1 は正規のGooglebot IPです (Domain: crawl-66-249-66-1.googlebot.com)

# Google bot IPではない場合
is-googlebot-ip 1.1.1.1
❌ 1.1.1.1 はGooglebot IPではありません

# 複数IPの場合
is-googlebot-ip 66.249.66.1 1.1.1.1
✅ 66.249.66.1 は正規のGooglebot IPです (Domain: crawl-66-249-66-1.googlebot.com)
❌ 1.1.1.1 はGooglebot IPではありません
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?