Skip to content

Instantly share code, notes, and snippets.

@JCotton1123
Last active Sep 14, 2020
Embed
What would you like to do?
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