Skip to content

Instantly share code, notes, and snippets.

@olvesh
Created October 19, 2016 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olvesh/b366877aa28f78d7b1f5acf961f1d8fd to your computer and use it in GitHub Desktop.
Save olvesh/b366877aa28f78d7b1f5acf961f1d8fd to your computer and use it in GitHub Desktop.
Find ip, subnet etc on AWS metadata service
#!/usr/bin/env bash
DOMAIN=$(curl -s http://169.254.169.254/latest/meta-data/hostname | perl -n -e'/[A-Za-z0-9-]+\.(.*)/ && print $1')
IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
MAC=$(curl -s http://169.254.169.254/latest/meta-data/mac)
CIDR=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/vpc-ipv4-cidr-block)
RECURSOR=$( echo $CIDR | awk -F"." '{print $1 "." $2 "." $3 ".2"}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment