Skip to content

Instantly share code, notes, and snippets.

@mikewebkist
Created February 12, 2014 16:55
Show Gist options
  • Save mikewebkist/8959625 to your computer and use it in GitHub Desktop.
Save mikewebkist/8959625 to your computer and use it in GitHub Desktop.
Get public IP addresses for all interfaces
#!/bin/bash
for ipinterface in `netstat -rn | awk '/^default/ { printf("%s-%s\n", $2, $NF) }'`; do
interface="${ipinterface##*-}"
ip="${ipinterface%%-*}"
echo -n "$interface "
case "${ip//[^\:\.]/}" in
'...')
curl -4 --interface $interface icanhazip.com ;;
':::::')
curl -6 --interface $interface icanhazip.com ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment