[olug] Unix Tip: GET YOUR IP-ADDRESS, Omaha Perl Mongers

Jeff Hinrichs jlh at cox.net
Sat Mar 22 19:35:08 UTC 2003


> Unix Guru Universe said:
> > Type this simple command at the unix-prompt
> > ifconfig | grep "inet addr" |  grep -v "127.0.0.1" | awk '{print $2;}' |
awk -F':' '{print $2;}'
>
> David Walker wrote:
> > If a user wished to know their IP address they can simply type ifconfig
>
> CM Miller wrote:
> > If they have an internet connection, then point browser to
http://whatismyip.com/
>
> --- Vincent <vincentr at cox.net> wrote:
> > The cookie is yours!
>
>
> Perl Monger solution:
>
> ifconfig | perl -ne '/dr:(\S+)/||next;(/127\.0\.0\.1/)||print"$1\n"'
>
> Density is good. I'm hoping to win one of the cookies Vincent mentioned
> in under an hour of labor. -grin-

Pythonista fashion:

 python -c "import socket; print socket.gethostbyname(socket.gethostname())"

+1 not reliant on ifconfig
+1 works on *nix/win/mac
+1 no regex's
Python: "Batteries Included"

Sorry, but the time it took to do this doesn't merit a cookie for me. ; )
-Jeff



More information about the OLUG mailing list