Finding IP addresses hidden in “ifconfig -a”
January 6, 2009 on 4:31 pm | In Apple, Linux | No CommentsWow…is it really over a year since my last blog post ?
Anyway, here’s something which I hope will be useful.
I find it awkward to pick out my Mac’s IP addresses at a glance from the output of “ifconfig -a”. Here’s a command-line that makes it very easy…
[eamonn@stig ~]$ ifconfig -a | perl -ne '$interface=$1 if (/^([a-z]+[0-9]+:)/); print "$interface $1\n" if (/inet (\d+\.\d+\.\d+\.\d+)/);'
lo0: 127.0.0.1
en0: 192.168.78.112
Now even the most commited command-line disciple is likely to baulk at typing all that, so I have an alias set up in ~/.bash_login. The quotes are a little fiddly to get right, so here’s the alias…
alias ipa='ifconfig -a | perl -ne '\''$interface=$1 if (/^([a-z]+[0-9]+:)/); print "$interface $1\n" if (/inet (\d+\.\d+\.\d+\.\d+)/);'\'
A slight variation of the same thing works on Linux also (with adjustments to compensate for the differences in output format)…
alias ipa='ifconfig -a | perl -ne '\''$interface=$1 if (/^([a-z]+[0-9]+) /); print "$interface $1\n" if (/inet addr:(\d+\.\d+\.\d+\.\d+)/);'\'
I hope its useful…
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^