mirror of
https://github.com/lord-alfred/ipranges.git
synced 2025-12-19 03:37:47 +00:00
29
.github/workflows/update.yml
vendored
Normal file
29
.github/workflows/update.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: "Update"
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '*/10 * * * *'
|
||||
# - cron: '8 */12 * * *' # At minute 8 past every 12th hour
|
||||
|
||||
jobs:
|
||||
updater:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Download Google IPs
|
||||
run: bash google/downloader.sh
|
||||
|
||||
- name: Commit files
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git config --local user.email "$(git log --format='%ae' HEAD^!)"
|
||||
git config --local user.name "$(git log --format='%an' HEAD^!)"
|
||||
git remote add github "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
|
||||
git pull github ${GITHUB_REF} --ff-only
|
||||
git add .
|
||||
if [ -z "$(git status --porcelain)" ]; then
|
||||
exit 0
|
||||
fi
|
||||
git commit -m "Update ip ranges"
|
||||
git push github HEAD:${GITHUB_REF}
|
||||
38
google/downloader.sh
Executable file
38
google/downloader.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
# https://cloud.google.com/compute/docs/faq#find_ip_range
|
||||
# From: https://github.com/pierrocknroll/googlecloud-iprange/blob/master/list.sh
|
||||
# From: https://gist.github.com/jeffmccune/e7d635116f25bc7e12b2a19efbafcdf8
|
||||
|
||||
set -euo pipefail
|
||||
set -x
|
||||
|
||||
|
||||
# get from public ranges
|
||||
curl -s https://www.gstatic.com/ipranges/goog.txt > /tmp/goog.txt
|
||||
curl -s https://www.gstatic.com/ipranges/cloud.json > /tmp/cloud.json
|
||||
|
||||
# get from netblocks
|
||||
txt="$(dig TXT _netblocks.google.com +short @8.8.8.8)"
|
||||
idx=2
|
||||
while [[ -n "${txt}" ]]; do
|
||||
echo "${txt}" | tr '[:space:]+' "\n" | grep ':' | cut -d: -f2- >> /tmp/netblocks.txt
|
||||
txt="$(dig TXT _netblocks${idx}.google.com +short @8.8.8.8)"
|
||||
((idx++))
|
||||
done
|
||||
|
||||
|
||||
# save ipv4
|
||||
grep -v ':' /tmp/goog.txt > /tmp/google-ipv4.txt
|
||||
jq '.prefixes[] | [.ipv4Prefix][] | select(. != null)' -r /tmp/cloud.json >> /tmp/google-ipv4.txt
|
||||
grep -v ':' /tmp/netblocks.txt >> /tmp/google-ipv4.txt
|
||||
|
||||
# save ipv6
|
||||
grep ':' /tmp/goog.txt > /tmp/google-ipv6.txt
|
||||
jq '.prefixes[] | [.ipv6Prefix][] | select(. != null)' -r /tmp/cloud.json >> /tmp/google-ipv6.txt
|
||||
grep ':' /tmp/netblocks.txt >> /tmp/google-ipv6.txt
|
||||
|
||||
|
||||
# sort & uniq
|
||||
sort -hu /tmp/google-ipv4.txt > google/ipv4.txt
|
||||
sort -hu /tmp/google-ipv6.txt > google/ipv6.txt
|
||||
Reference in New Issue
Block a user