Skip to content

Instantly share code, notes, and snippets.

@Laxman-SM
Forked from haukurk/myips.sh
Created August 11, 2023 04:07
Show Gist options
  • Save Laxman-SM/fa7529244fbf8488f16ffda2380fbf65 to your computer and use it in GitHub Desktop.
Save Laxman-SM/fa7529244fbf8488f16ffda2380fbf65 to your computer and use it in GitHub Desktop.
cli myips
# return my IP addresses
function myip() {
ExtIP=`dig TXT +short o-o.myaddr.l.google.com @ns1.google.com`
echo $ExtIP | tr -d '"' | awk '{print "external : " $1}'
ifconfig lo0 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "lo0 : " $2}'
ifconfig en0 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "en0 (IPv4): " $2 " " $3 " " $4 " " $5 " " $6}'
ifconfig en0 | grep 'inet6 ' | sed -e 's/ / /' | awk '{print "en0 (IPv6): " $2 " " $3 " " $4 " " $5 " " $6}'
ifconfig en1 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "en1 (IPv4): " $2 " " $3 " " $4 " " $5 " " $6}'
ifconfig en1 | grep 'inet6 ' | sed -e 's/ / /' | awk '{print "en1 (IPv6): " $2 " " $3 " " $4 " " $5 " " $6}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment