From 8b0d41b023e704d975ef9db54dd1d0f7b5a34692 Mon Sep 17 00:00:00 2001 From: NavyStack <137406386+NavyStack@users.noreply.github.com> Date: Sat, 3 Feb 2024 08:52:24 +0900 Subject: [PATCH] Update google.sh --- googlebot/google.sh | 48 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/googlebot/google.sh b/googlebot/google.sh index 462d7cb0..94dcf741 100755 --- a/googlebot/google.sh +++ b/googlebot/google.sh @@ -1,20 +1,52 @@ #!/bin/bash +# Define file paths +json_file="/tmp/googlebot.json" +ipv4_file="/tmp/googlebot-ipv4.txt" +ipv6_file="/tmp/googlebot-ipv6.txt" +ipv4_output="googlebot/ipv4.txt" +ipv6_output="googlebot/ipv6.txt" +ipv4_comma_output="googlebot/ipv4_comma.txt" +ipv6_comma_output="googlebot/ipv6_comma.txt" + # Public GoogleBot IP ranges -curl -s https://developers.google.com/search/apis/ipranges/googlebot.json > /tmp/googlebot.json +curl -s https://developers.google.com/search/apis/ipranges/googlebot.json > "$json_file" + +# Check if curl command was successful +if [ $? -ne 0 ]; then + echo "Error: Failed to download GoogleBot IP ranges." + exit 1 +fi # Save IPv4 -jq '.prefixes[] | [.ipv4Prefix][] | select(. != null)' -r /tmp/googlebot.json > /tmp/googlebot-ipv4.txt +jq '.prefixes[] | [.ipv4Prefix][] | select(. != null)' -r "$json_file" > "$ipv4_file" # Save IPv6 -jq '.prefixes[] | [.ipv6Prefix][] | select(. != null)' -r /tmp/googlebot.json > /tmp/googlebot-ipv6.txt +jq '.prefixes[] | [.ipv6Prefix][] | select(. != null)' -r "$json_file" > "$ipv6_file" + +# Sort and Uniq for IPv4 +sort -V "$ipv4_file" | uniq > "$ipv4_output" -# Sort and Uniq -sort -V /tmp/googlebot-ipv4.txt | uniq > googlebot/ipv4.txt -sort -V /tmp/googlebot-ipv6.txt | uniq > googlebot/ipv6.txt +# Check if sort command was successful +if [ $? -ne 0 ]; then + echo "Error: Failed to sort IPv4 addresses." + exit 1 +fi + +# Sort and Uniq for IPv6 +sort -V "$ipv6_file" | uniq > "$ipv6_output" + +# Check if sort command was successful +if [ $? -ne 0 ]; then + echo "Error: Failed to sort IPv6 addresses." + exit 1 +fi # Save IPv4 with comma separation -jq -r '.prefixes[] | [.ipv4Prefix][] | select(. != null)' /tmp/googlebot.json | sort -V | uniq | paste -sd "," - > googlebot/ipv4_comma.txt +jq -r '.prefixes[] | [.ipv4Prefix][] | select(. != null)' "$json_file" | sort -V | uniq | paste -sd "," - > "$ipv4_comma_output" # Save IPv6 with comma separation -jq -r '.prefixes[] | [.ipv6Prefix][] | select(. != null)' /tmp/googlebot.json | sort -V | uniq | paste -sd "," - > googlebot/ipv6_comma.txt \ No newline at end of file +jq -r '.prefixes[] | [.ipv6Prefix][] | select(. != null)' "$json_file" | sort -V | uniq | paste -sd "," - > "$ipv6_comma_output" + +# Clean up temporary files +rm "$json_file" "$ipv4_file" "$ipv6_file"