Skip to content

Instantly share code, notes, and snippets.

@JCotton1123
Last active March 15, 2023 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JCotton1123/1c77e398ee2175bd6d0f2c5fa3b139bd to your computer and use it in GitHub Desktop.
Save JCotton1123/1c77e398ee2175bd6d0f2c5fa3b139bd to your computer and use it in GitHub Desktop.
AWS Export IP Addresses
# Export IP addresses to support vulnerability scanning
# Public IPs
touch /tmp/public-ips.txt
aws ec2 describe-instances \
--query "Reservations[*].Instances[*].PublicIpAddress" \
--output=text \
>>/tmp/public-ips.txt
aws ec2 describe-addresses | \
jq -r .Addresses[].PublicIp \
>>/tmp/public-ips.txt
aws elbv2 describe-load-balancers | \
jq -r '.LoadBalancers[] | select(.Scheme == "internet-facing").DNSName' | \
xargs -L1 -I {} sh -c "dig +short {} | head -n 1" \
>>/tmp/public-ips.txt
cat /tmp/public-ips.txt | sort | uniq
# Private IPs
touch /tmp/private-ips.txt
# All IPs, including duplicates
# aws ec2 describe-network-interfaces | \
# jq -r .NetworkInterfaces[].PrivateIpAddress \
# >>/tmp/private-ips.txt
# EC2 server & internal load-balancer IPs
aws ec2 describe-instances \
--query "Reservations[*].Instances[*].PrivateIpAddress" \
--output=text \
>>/tmp/private-ips.txt
aws elbv2 describe-load-balancers | \
jq -r '.LoadBalancers[] | select(.Scheme == "internal").DNSName' | \
xargs -L1 -I {} sh -c "dig +short {} | head -n 1" \
>>/tmp/private-ips.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment