Skip to content

Commit

Permalink
Retrieve local ip for currently active interface
Browse files Browse the repository at this point in the history
Signed-off-by: Merlin Rabens <[email protected]>
  • Loading branch information
merlinrabens committed Aug 23, 2019
1 parent c80e05b commit e99d49a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 0 additions & 1 deletion .aliases
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ alias canary='/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Ch

# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="echo $(ifconfig -a | grep -E 'UP|inet[^6]' | grep -A1 UP | grep inet | grep -v 127 | tail -1 | awk '{print $2}')"
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"

# Show active network interfaces
Expand Down
6 changes: 6 additions & 0 deletions .functions
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,9 @@ function o() {
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}

# echo the IP address for the currently active network interface
function localip() {
local activeIf=$(netstat -rn | grep default | awk '{print $NF}' | head -1)
ipconfig getifaddr ${activeIf}
}

0 comments on commit e99d49a

Please sign in to comment.