From cca54a01f76721e08a8186872cb32da16408910a Mon Sep 17 00:00:00 2001 From: Lord Alfred <2259979+lord-alfred@users.noreply.github.com> Date: Thu, 29 Jul 2021 14:57:08 +0300 Subject: [PATCH] Google IPs (#1) * rename * Add google ip downloader --- .github/workflows/update.yml | 29 +++++++++++++++++++++++++++ README.md | 2 +- google/downloader.sh | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update.yml create mode 100755 google/downloader.sh diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 00000000..c56e9438 --- /dev/null +++ b/.github/workflows/update.yml @@ -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} diff --git a/README.md b/README.md index 0dc7af46..bd269aa3 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# ipranges \ No newline at end of file +# IPRanges \ No newline at end of file diff --git a/google/downloader.sh b/google/downloader.sh new file mode 100755 index 00000000..c8400faa --- /dev/null +++ b/google/downloader.sh @@ -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