Skip to content

Instantly share code, notes, and snippets.

@duckworth
Forked from JCotton1123/export.sh
Created July 7, 2022 15:48
Show Gist options
  • Save duckworth/64322c8f6f465629c2f6dd9273ffbc44 to your computer and use it in GitHub Desktop.
Save duckworth/64322c8f6f465629c2f6dd9273ffbc44 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