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

Jay Hannah jay at jays.net
Sat Mar 22 21:25:47 UTC 2003


> > ifconfig | perl -ne '/dr:(\S+)/||next;(/127\.0\.0\.1/)||print"$1\n"'

Jeff Hinrichs wrote:
>  python -c "import socket; print socket.gethostbyname(socket.gethostname())"
> 
> +1 not reliant on ifconfig
> +1 works on *nix/win/mac
> +1 no regex's

- But my machine has 16 IPs, and your solution only returns one of them.
The one that happens to be associated with my "hostname". And when
you're running 281 domains, "hostname" seems irrelevant.
- Mac? $ip{WinX} = "DHCP"; -grin-
- But I like regex's!

> Python: "Batteries Included"

I'm totally ignorant about Python. I wonder how similar Python and Perl
6 will be?

Where's our Ruby expert? S/he should chime in here... -grin-

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

Boo!!  -grin-

j

Omaha Perl Mongers: http://omaha.pm.org


More information about the OLUG mailing list