Check own IP in shell script

Dec 16 2011 Published under Linux

ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

Perl:

ifconfig -a | perl -ne 'if ( m/^\s*inet (?:addr:)?([\d.]+).*?cast/ ) { print qq($1\n); exit 0; }'

ref:
http://www.cyberciti.biz/tips/read-unixlinux-system-ip-address-in-a-shell-script.html
http://www.cyberciti.biz/faq/perl-finding-my-unix-linux-ip-address/

No responses yet

Comments are closed at this time.

Login