Skip to content

Commit

Permalink
Update google.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
NavyStack authored Feb 2, 2024
1 parent 4dec398 commit 8b0d41b
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions googlebot/google.sh
Original file line number Diff line number Diff line change
@@ -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
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"

0 comments on commit 8b0d41b

Please sign in to comment.