Skip to content

Instantly share code, notes, and snippets.

@kntyskw
Last active June 13, 2024 22:46
Show Gist options
  • Select an option

  • Save kntyskw/5413698 to your computer and use it in GitHub Desktop.

Select an option

Save kntyskw/5413698 to your computer and use it in GitHub Desktop.

Revisions

  1. kntyskw revised this gist Apr 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Get neighbour mac addresses
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,4 @@ MY_SUBNET_ID=`curl http://169.254.169.254/latest/meta-data/network/interfaces/ma
    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 -v $MY_MAC_ADDR | cut -f 11 | tr "\\n" " "
    ec2-describe-network-interfaces --region $MY_REGION | grep $MY_SUBNET_ID | grep in-use | grep -v $MY_MAC_ADDR | cut -f 11 | tr "\\n" " "
  2. kntyskw revised this gist Apr 18, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Get neighbour mac addresses
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,11 @@ IF=$1
    # Gets MAC address of the interface
    MY_MAC_ADDR=`ip link show $IF | awk '/ether/ {print $2}'`

    # Get subnet ID
    # 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 -v $MY_MAC_ADDR | cut -f 11 | tr "\\n" " "
  3. kntyskw created this gist Apr 18, 2013.
    12 changes: 12 additions & 0 deletions Get neighbour mac addresses
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #!/bin/sh

    IF=$1

    # Gets MAC address of the interface
    MY_MAC_ADDR=`ip link show $IF | awk '/ether/ {print $2}'`

    # Get subnet ID
    MY_SUBNET_ID=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MY_MAC_ADDR/subnet-id 2> /dev/null`
    MY_REGION=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null | rev | cut -c 2- | rev`

    ec2-describe-network-interfaces --region $MY_REGION | grep $MY_SUBNET_ID | grep -v $MY_MAC_ADDR | cut -f 11 | tr "\\n" " "