Skip to content

Instantly share code, notes, and snippets.

@kntyskw
Last active November 10, 2022 06:39
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 kntyskw/5413698 to your computer and use it in GitHub Desktop.
Save kntyskw/5413698 to your computer and use it in GitHub Desktop.
#!/bin/sh
IF=$1
# Gets MAC address of the interface
MY_MAC_ADDR=`ip link show $IF | awk '/ether/ {print $2}'`
# Get the ID of the subnet that the interface is connected to
MY_SUBNET_ID=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MY_MAC_ADDR/subnet-id 2> /dev/null`
# Get the current region that the instance resides in
MY_REGION=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null | rev | cut -c 2- | rev`
# Get the list of MAC addresses of the ENIs in the same subnet
ec2-describe-network-interfaces --region $MY_REGION | grep $MY_SUBNET_ID | grep in-use | grep -v $MY_MAC_ADDR | cut -f 11 | tr "\\n" " "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment