Last active
June 13, 2024 22:46
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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