Skip to content

Commit e99d49a

Browse files
committed
Retrieve local ip for currently active interface
Signed-off-by: Merlin Rabens <m.rabens@hotmail.de>
1 parent c80e05b commit e99d49a

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

.aliases

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ alias canary='/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Ch
5757

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

6362
# Show active network interfaces

.functions

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,9 @@ function o() {
169169
function tre() {
170170
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
171171
}
172+
173+
# echo the IP address for the currently active network interface
174+
function localip() {
175+
local activeIf=$(netstat -rn | grep default | awk '{print $NF}' | head -1)
176+
ipconfig getifaddr ${activeIf}
177+
}

0 commit comments

Comments
 (0)