Skip to content

Instantly share code, notes, and snippets.

@jayhding
Created August 30, 2019 00:12
Show Gist options
  • Save jayhding/71f7d9de48c5b5bb718505e4380d78a9 to your computer and use it in GitHub Desktop.
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
#!/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