Last active
October 31, 2022 04:49
-
-
Save ushitora-anqou/527197da0b2d99dfb35cc4ab3cdfd974 to your computer and use it in GitHub Desktop.
GCPのファイアウォールに中国とオーストラリアからの上り通信を弾く設定を追加するシェルスクリプト
This file contains hidden or 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
| #!/bin/bash | |
| # | |
| # Shell script to add GCP's firewall to deny all ingress from China and Australia. | |
| # Author: Ushitora Anqou | |
| # License: MIT | |
| # | |
| curl https://ipv4.fetus.jp/cn.txt | grep -vE '#|^$' > cn.txt | |
| curl https://ipv4.fetus.jp/au.txt | grep -vE '#|^$' > au.txt | |
| for i in $(seq 1 250 $(wc -l cn.txt | cut -d' ' -f1)); do sed -n "$i,$((249 + i))p" cn.txt > cn-$(echo $i | awk '{printf "%02d", ($1-1)/250}'); done | |
| for i in $(seq 1 250 $(wc -l au.txt | cut -d' ' -f1)); do sed -n "$i,$((249 + i))p" au.txt > au-$(echo $i | awk '{printf "%02d", ($1-1)/250}'); done | |
| ls cn-* au-* | while read fn; do | |
| gcloud compute firewall-rules create "deny-$fn" --action deny --network default --priority 100 --rules all\ | |
| --source-ranges $(paste -s -d ',' $fn) | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment