#!/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" " "