-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
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" |