Skip to content

Instantly share code, notes, and snippets.

@pete-caylent
Last active March 21, 2023 23:32
Show Gist options
  • Save pete-caylent/05c5cd60abc99794e3c591b439c950bc to your computer and use it in GitHub Desktop.
Save pete-caylent/05c5cd60abc99794e3c591b439c950bc to your computer and use it in GitHub Desktop.
Get AWS ENI Info based on private DNS name
aws ec2 describe-network-interfaces \
--filter Name=private-dns-name,Values=ip-10-32-6-29.us-gov-west-1.compute.internal \
--query 'NetworkInterfaces[].[Attachment.InstanceOwnerId, AvailabilityZone, Description, PrivateIpAddress, SubnetId, VpcId]'
## Result (nested output)
# [
# [
# "amazon-elasticsearch",
# "us-gov-west-1a",
# "ES dev",
# "10.32.6.29",
# "subnet-xxxxxxxxx",
# "vpc-xxxxxxxx"
# ]
# ]
aws ec2 describe-network-interfaces \
--filter Name=private-dns-name,Values=ip-10-32-6-29.us-gov-west-1.compute.internal \
| jq -r '.NetworkInterfaces[] | .AvailabilityZone, .Description, .PrivateIpAddress, .SubnetId, .VpcId'
## Result (raw output)
# us-gov-west-1a
# ES dev
# 10.32.6.29
# subnet-xxxxxxxxx
# vpc-xxxxxxxxx
aws ec2 describe-network-interfaces \
--filter Name=private-dns-name,Values=ip-10-32-6-29.us-gov-west-1.compute.internal \
| jq -r '.NetworkInterfaces[] | [.AvailabilityZone, .Description, .PrivateIpAddress, .SubnetId, .VpcId]'
## Result (array)
# [
# "us-gov-west-1a",
# "ES dev",
# "10.32.6.29",
# "subnet-xxxxxxxxx",
# "vpc-xxxxxxxxx"
# ]
@pete-caylent
Copy link
Author

Sometimes 3rd party security scanning tools can put you in a predicament where you need to find info about a host, and you only have a private DNS name to play with.

These AWS CLI commands will return info about an AWS Elastic Network Interface (ENI) in a given AWS account in a given AWS region, based on the private DNS name value that you provide.

In some cases, you may want to leverage this info programmatically so it can be input elsewhere e.g. a CI/CD pipeline or
other tool/target.

These examples show how you can use AWS CLI built-in query syntax, or alternatively, something like jq, to return the info in the format you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment