Skip to content

Instantly share code, notes, and snippets.

@stzhng

stzhng/ssh rule

Last active Jun 5, 2020
Embed
What would you like to do?
Generate SSH IP Allow-list
#!/bin/sh
set -- $(dig -t txt +short _cloud-netblocks.googleusercontent.com +trace)
included="" ip4=""
while [ $# -gt 0 ]; do
k="${1%%:*}" v="${1#*:}"
case "$k" in
include)
# only include once
if [ "${included% $v *}" = "${included}" ]; then
set -- "$@" $(dig -t txt +short "$v")
included=" $v $included"
fi
;;
ip4) ip4="$v $ip4" ;;
esac
shift
done
sip4=""
for i in $ip4; do
# printf "$i,"
sip4=$i,$sip4
done
echo $sip4
CMD="gcloud compute firewall-rules create ssh-rule --allow=tcp:22 --source-ranges=${sip4} --network gridz"
echo $CMD
$CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.