Created
August 26, 2025 07:04
-
-
Save parsibox/ab56e211dfffcbd0cc24d69e18fca691 to your computer and use it in GitHub Desktop.
allow Googlebot ip range in csf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget https://developers.google.com/search/apis/ipranges/googlebot.json | |
grep -Eho '((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(\/(3[0-2]|[12]?[0-9]))?' /root/davari/googlebot.json | sort -u | sort -u | xargs -r -n1 -I{} csf -a "{}" " Googlebot " | |
sudo csf -a 66.249.0.0/16 "Googlebot range" | |
sudo cp /etc/csf/csf.allow{,.bak.$(date +%F-%H%M%S)} && \ | |
sudo awk 'BEGIN{keep="66.249.0.0/16"} | |
function is_sub66(ip){ return ip ~ /^66\.249\.[0-9]{1,3}\.[0-9]{1,3}(\/([0-9]|[12][0-9]|3[0-2]))?$/ } | |
{ | |
orig=$0 | |
ip=$1 | |
# خطوط ساده: اگر آیپی/سایدر داخل 66.249.*.* باشد و دقیقا /16 نباشد، حذفش کن | |
if (ip != "" && is_sub66(ip) && ip != keep) next | |
# خطوط پیشرفته (قالب tcp|in|...|s=IP): اگر s= داخل 66.249.*.* و ≠ /16 بود، حذفش کن | |
if (match($0, /(^|[|,])s=([0-9.]+(\/[0-9]+)?)/, m)) { | |
sip=m[2]; if (is_sub66(sip) && sip != keep) next | |
} | |
print orig | |
}' /etc/csf/csf.allow | sudo tee /etc/csf/csf.allow.new >/dev/null && \ | |
sudo mv /etc/csf/csf.allow.new /etc/csf/csf.allow && \ | |
sudo csf -r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment