Re: How to determine local IP
It may not be pretty, but this will be faster:
ifconfig | \
awk '/inet addr:/ {sub(".*:","",$2) ; if ($2 !~ /^127/) { print $2 }}'
On Tue, Jun 22, 1999 at 10:34:23PM +1000, Shao Zhang wrote
> What about this one??
>
> ifconfig | \
> grep "inet addr" | \
> grep -v "127.0.0.1" | \
> awk '{print $2;}' | \
> awk -F':' '{print $2;}'
>
>
> On Mon, Jun 21, 1999 at 11:23:29PM -0500, R. Brock Lynn wrote:
> > 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/);'
> >
> > oohh nifty. Now let's see if I can figure out how it works. :)
> > (no don't tell me now! I took the usenix perl tutorials... I should know... :\
> >
> > --Brock
Each command in the pipeline requires a fork and exec, so the fewer commands
the better. Since I'm bored, some stats:
Time for a null command (:) in a subshell:
real 0m0.019s
user 0m0.010s
sys 0m0.010s
Time for running ifconfig in a subshell:
real 0m0.236s
user 0m0.160s
sys 0m0.030s
Time for Shao Zang's pipeline, in a subshell:
real 0m0.274s
user 0m0.210s
sys 0m0.020s
Time for my pipeline, in a subshell:
real 0m0.243s
user 0m0.190s
sys 0m0.000s
Time for lunch,
John P.
--
huiac@camtech.net.au
john@huiac.apana.org.au
"Oh - I - you know - my job is to fear everything." - Bill Gates in Denmark
Reply to: