Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: how do I find my IP address

In message <20040614115736.GJ19941@xxxxxxxxxxxxx>
on Mon, Jun 14, 2004 at 01:57:36PM +0200, Vincent Lefevre wrote:
> On 2004-06-13 23:37:08 -0400, Jason Price wrote:
> > On most unix flavors, some varient of:
> > ifconfig -a | grep inet | grep -v '' | awk '{print $2}'
> > should work.
> Not under linux. This is still OS-dependent. With ifconfig, you
> probably need to filter on \d+\.\d+\.\d+\.\d+ in particular.
> BTW, can zsh do such things internally (without using external
> programs like sed or perl)?

Well, for string manipulation, you can use zsh expressions (e.g. loops,
pattern matching and string manipulation) rather than relying on sed or
awk, if that is what you're asking.

If you're asking whether zsh can "find out your IP address", that's a
bigger problem, with no "correct" answer in the general case. For a
start, do you want your host's IPv4 address or its IPv6 address? And for
which interface (loopback, PPP, Ethernet, or secure tunnel)? And what if
you have multiple Ethernet interfaces, or if you have multiple subnets
and aliases (e.g. your machine has a "private" address as well as public
address)? And so on. Although each machine has a "hostname", there are
potentially many addresses that represent that host. I suppose there
might be some "standard" resolver library routines that could return
just a single IP address, and this would work for "most people". But,
even so, my guess is that this sort of network information might still
be best left as part of an optional zsh module if at all.

Don't forget that zsh has a 'periodic' function that could be used to
retest a host's IP address every 5 mins, for instance, as an alternative
to invoking `ifconfig` every time the prompt is generated.

Messages sorted by: Reverse Date, Date, Thread, Author