extract IP address and feed it into a command

DJ Boris dj_boris at mail.ru
Tue Apr 29 02:08:38 PDT 2003

hi guys,

I would like to thank you for all your help... you pointed me in the right
direction. here is what worked for me:

ifconfig tun0 | grep xxx.x | cut -d " " -f2
ifconfig tun0 | grep xxx.x | awk '/inet/ {print $2}'
ifconfig tun0 | grep xxx.x | awk '{print $2}'

xxx.x - this is the first part of my IP. it always starts with that xxx.x
number. grep gets it from the ifconfig and then all it takes is string


dj boris

----- Original Message -----
From: "Christian Stigen Larsen" <csl at sublevel3.org>
To: <freebsd-questions at freebsd.org>
Sent: Tuesday, April 29, 2003 12:31 AM
Subject: Re: extract IP address and feed it into a command

> Quoting DJ Boris (dj_boris at mail.ru):
> | I need to extract my IP address [...] assigned by my ISP [...]
> | I know that my IP always starts with zzz.zzz and if I run
> |
> | "ifconfig | grep zzz.zzz"
> >From the top of my head, I don't know any programs that automatically
> out IP addresses.  But you could always combine ifconfig with awk.  Say
> interface you need to query is xl0, then you might do:
> $ ifconfig xl0 inet | awk '/inet/ {print $2}'
> This prints "", which is the IP assigned to my box by the DHCP
> I don't know if this is exactly what you need, but at least it should give
> some idea on using awk in such cases.  Play around, and you'll probably
> something working (or, possibly, someone else on the list gives you some
> better alternative).
> Dig up some info on awk if you've never heard about it before.
> --
> Christian Stigen Larsen -- http://sublevel3.org/~csl/ -- mob: +47 98 22 02
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
"freebsd-questions-unsubscribe at freebsd.org"

More information about the freebsd-questions mailing list