Skip to content

Instantly share code, notes, and snippets.

@tragulum
Last active December 29, 2023 13:18
Show Gist options
  • Save tragulum/2c9ba8e7ea8ca3a0c00da37fdc80423d to your computer and use it in GitHub Desktop.
Save tragulum/2c9ba8e7ea8ca3a0c00da37fdc80423d to your computer and use it in GitHub Desktop.
VPC and VPC Peering Enum Script
#!/bin/bash
# Default values
profile="default"
region="us-east-1" # Replace with your default region
# Function to display script usage
usage() {
echo "Usage: $0 -p <profile> -r <region>"
echo "Options:"
echo " -p <profile> AWS profile name from .aws/credentials file"
echo " -r <region> AWS region"
exit 1
}
# Parse command line options
while getopts ":p:r:" opt; do
case $opt in
p)
profile="$OPTARG"
;;
r)
region="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# Retrieve VPC information
vpcs=$(aws ec2 describe-vpcs --profile "$profile" --region "$region")
# Retrieve VPC peering connections
peering_connections=$(aws ec2 describe-vpc-peering-connections --profile "$profile" --region "$region")
# Output information to file
echo "VPCs:" > vpc-out.txt
echo "$vpcs" >> vpc-out.txt
echo "" >> vpc-out.txt
echo "VPC Peering Connections:" >> vpc-out.txt
echo "$peering_connections" >> vpc-out.txt
echo "Information written to vpc-out.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment