Re: How to determine local IP
*- On 21 Jun, Brad wrote about "Re: How to determine local IP"
> On Mon, 21 Jun 1999, scratch wrote:
>
>> On Mon, 21 Jun 1999, R. Brock Lynn wrote:
>>
>> > > /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d" " -f1
>> >
>> > nice, now can you do that with a perl one-liner? :)
>>
>> Something like this?
>> perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s/);'
>
> Beat me to it! Oh well, i can clean it up to make it work right...
> perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s P-t-P:/, "\n");'
>
> Or how about one for every interface? This seems to work...
> perl -e 'for(`/sbin/ifconfig`){/^\S+/ and $i=$& or /inet addr:(\S+)/ and print"$i\t$1\n"}'
>
> If you don't want the interface name, it gets even shorter:
> perl -e 'for(`/sbin/ifconfig`){/inet addr:(\S+)/ and print"$1\n"}'
>
I HAVE to learn Perl!!!!!!!! These are sooooooo much faster than the
grep/awk/cut hacks that I and others have thrown out in this thread. I
love *nix and all its tools.
--
Brian
---------------------------------------------------------------------
Mechanical Engineering servis@purdue.edu
Purdue University http://www.ecn.purdue.edu/~servis
---------------------------------------------------------------------
Reply to: