Get readable list of network IPs - problem
lindskogen opened this issue · 3 comments
lindskogen commented
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"
This alias gives me some trouble, when I try to run the alias it prints the full line instead of just the ip. What's weird is that when I run the command like this:
ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'
It works without any problems. Any solutions?
gf3 commented
I don't think you got that one from my dotfiles. However, this is easily fixed sans perl.
ifconfig -a | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+'
If you also want the interface name, you could use something like the following, just be sure to change the range to match the number of interfaces you have (I have two):
for i in {0..1}; do echo "en$i → $(ipconfig getifaddr en$i)"; done
lindskogen commented
Whoops, sorry! I posted in the wrong repo... Thank you very much for helping out anyways!
Btw, ended up using the following:
ifconfig -a | grep -o 'inet [0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+' | sed s/inet\ //g
gf3 commented
Woo, excellent!