Created
August 30, 2019 00:12
-
-
Save jayhding/71f7d9de48c5b5bb718505e4380d78a9 to your computer and use it in GitHub Desktop.
This script is used to find specific public IP by looping all GCP projects
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
#!/usr/bin/env bash | |
# This script finds specific public ip from all of your GCP projects | |
PUBLIC_IP=$1 | |
for projct in $(gcloud projects list | awk '{print $1}' | sed -n '1!p'); do | |
echo "-- Searching in $projct" | |
gcloud config set project "$projct" >> /dev/null 2>&1 | |
for ip in $(gcloud --format="value(networkInterfaces[0].accessConfigs[0].natIP)" compute instances list); do | |
if [ "$ip" = "$PUBLIC_IP" ]; then | |
echo "Found ip $PUBLIC_IP in project $projct" | |
break | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment