zsh-users
 help / color / mirror / code / Atom feed
* Re: how do I find my IP address
@ 2004-06-14  1:30 William Scott
  2004-06-14  3:37 ` Jason Price
  2004-06-14  3:57 ` Timothy Luoma
  0 siblings, 2 replies; 7+ messages in thread
From: William Scott @ 2004-06-14  1:30 UTC (permalink / raw)
  To: lists; +Cc: zsh-users

Timothy:

If you are running a computer with an ip address that changes 
(dynamically allocated), this will work, although it is kind of ugly:

define an alias such as:

alias myip="curl -s http://www.showmyip.com/simple/ | awk '{print $1}'  
"



I would echo the output of myip into something at login rather than 
grab it off the internet every time I hit the return key.


If you have a static ip address, you should only have to figure this 
out once.   On Mac OS X you can find this in the System Preferences 
under file sharing or network settings (I am assuming this on the basis 
of the Micro$oft email stamp at the bottom of your email.)

This alias and a whole bunch of stuff that is useful for OS X zsh is 
distributed by Gary Kerbaugh.  I have links to it and a few of my own 
zsh functions here:  http://tinyurl.com/3373b

Bill Scott


  http://www.apple.com/trailers/lions_gate/fahrenheit_911/




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how do I find my IP address
  2004-06-14  1:30 how do I find my IP address William Scott
@ 2004-06-14  3:37 ` Jason Price
  2004-06-14 10:58   ` Jussi Pakkanen
  2004-06-14 11:57   ` Vincent Lefevre
  2004-06-14  3:57 ` Timothy Luoma
  1 sibling, 2 replies; 7+ messages in thread
From: Jason Price @ 2004-06-14  3:37 UTC (permalink / raw)
  To: William Scott, zsh-users

On most unix flavors, some varient of:

ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{print $2}'

should work.  'ifconfig' can live in various places, but usually it
is in /sbin/ifconfig or /usr/sbin/ifconfig (old unixen might have it
in /etc/ifconfig).

The 'grep inet' should give you all the ip addresses, but will also
have things like netmask.  The 'grep -v 127.0.0.1' will cut out the
localhost definition.  The 'awk '{print $2}' should give you just the
IP address, but it might be in a different field (try 3, 4, etc).

I'm sure there's a way to figure out a pure zsh way to do this, but I 
don't know it.  Also, I strongly suggest figuring this out once,
stashing it in a variable ($MY_IP or some such), and just using that 
variable.

If you're under windows, under cygwin, you're on your own, but I'd
start with 'ipconfig /all'.

--Jason

On Sun, Jun 13, 2004 at 06:30:23PM -0700, William Scott wrote:
> Timothy:
> 
> If you are running a computer with an ip address that changes 
> (dynamically allocated), this will work, although it is kind of ugly:
> 
> define an alias such as:
> 
> alias myip="curl -s http://www.showmyip.com/simple/ | awk '{print $1}'  
> "
> 
> 
> 
> I would echo the output of myip into something at login rather than 
> grab it off the internet every time I hit the return key.
> 
> 
> If you have a static ip address, you should only have to figure this 
> out once.   On Mac OS X you can find this in the System Preferences 
> under file sharing or network settings (I am assuming this on the basis 
> of the Micro$oft email stamp at the bottom of your email.)
> 
> This alias and a whole bunch of stuff that is useful for OS X zsh is 
> distributed by Gary Kerbaugh.  I have links to it and a few of my own 
> zsh functions here:  http://tinyurl.com/3373b
> 
> Bill Scott
> 
> 
>   http://www.apple.com/trailers/lions_gate/fahrenheit_911/
> 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how do I find my IP address
  2004-06-14  1:30 how do I find my IP address William Scott
  2004-06-14  3:37 ` Jason Price
@ 2004-06-14  3:57 ` Timothy Luoma
  1 sibling, 0 replies; 7+ messages in thread
From: Timothy Luoma @ 2004-06-14  3:57 UTC (permalink / raw)
  To: William Scott; +Cc: zsh-users

On 6/13/04 9:30 PM, "William Scott" <wgscott@chemistry.ucsc.edu> wrote:

> If you are running a computer with an ip address that changes
> (dynamically allocated), this will work, although it is kind of ugly:
> 
> define an alias such as:
> 
> alias myip="curl -s http://www.showmyip.com/simple/ | awk '{print $1}'
> "

Ah, no good.  This shows my public IP address (the official internet IP
given to me by my ISP when I am dialed up).

[My apologies for being too vague.  I hope I haven't wasted anyone's time]

> If you have a static ip address, you should only have to figure this
> out once. 

I'm actually on two private LANs (one home and one work)... home uses
10.x.x.x and work uses 192.168.x.x but they are both given out via DHCP.


Right now the ugly hack I have is this:

    ifconfig en1 | fgrep 'inet ' | awk '{print $2}'

which works for the Mac, but it would have to be

    ifconfig eth0 | fgrep 'inet ' | awk '{print $2}' |\
    sed 's/addr://'

on Fedora, and possibly even something ELSE for FreeBSD.  Obviously less
than ideal to have to keep hacking several different ways of doing this, but
if that's the only way...


> On Mac OS X you can find this in the System Preferences
> under file sharing or network settings (I am assuming this on the basis
> of the Micro$oft email stamp at the bottom of your email.)

Ah yes, sorry about that.  I saved about $340USD by waiting for Office:2004
to hit the Microsoft employee store, so I've been using the demo version
while waiting.  I should have an official copy soon (aside: I've never liked
Word or Office but Office:Mac 2004 is quite nice).

[no, I'm not an MS employee, but a friend of mine is]

Anyway, I'm running zsh on Fedora, FreeBSD, and Mac OSX. (I actually just
got my old Dell 7500 setup to dual boot XP/Fedora/FreeBSD today, which is
what prompted the question.  I'm all of a sudden going to need/want to know
several bits of information which I haven't needed to know before.

The real challenge is going to be to see if I can write one .zshrc which I
can use on all my difference zsh shell accounts by use of conditional
statements.

> This alias and a whole bunch of stuff that is useful for OS X zsh is
> distributed by Gary Kerbaugh.  I have links to it and a few of my own
> zsh functions here:  http://tinyurl.com/3373b

Cool, will check it out.

Thanks

TjL

Sent using the Microsoft Entourage 2004 for Mac Test Drive.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how do I find my IP address
  2004-06-14  3:37 ` Jason Price
@ 2004-06-14 10:58   ` Jussi Pakkanen
  2004-06-14 11:57   ` Vincent Lefevre
  1 sibling, 0 replies; 7+ messages in thread
From: Jussi Pakkanen @ 2004-06-14 10:58 UTC (permalink / raw)
  To: zsh-users


--- Jason Price <jprice@cyberbuzz.gatech.edu> wrote:

> On most unix flavors, some varient of:
> 
> ifconfig -a | grep inet | grep -v '127.0.0.1' | awk
> '{print $2}'
> 
> should work.  'ifconfig' can live in various places,
> but usually it
> is in /sbin/ifconfig or /usr/sbin/ifconfig (old
> unixen might have it in /etc/ifconfig).

> I'm sure there's a way to figure out a pure zsh way
> to do this, but I don't know it. 

The purest I could think of was eliminating awk, which
can be done like this:

foo=`ifconfig | grep inet | grep -v '127.0.0.1'`
baz=($=foo)

Now $baz[2] contains the ip address. I guess you could
get the address by poking /proc, but that's not very portable.


	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how do I find my IP address
  2004-06-14  3:37 ` Jason Price
  2004-06-14 10:58   ` Jussi Pakkanen
@ 2004-06-14 11:57   ` Vincent Lefevre
  2004-06-14 12:23     ` James Devenish
  1 sibling, 1 reply; 7+ messages in thread
From: Vincent Lefevre @ 2004-06-14 11:57 UTC (permalink / raw)
  To: zsh-users

On 2004-06-13 23:37:08 -0400, Jason Price wrote:
> On most unix flavors, some varient of:
> 
> ifconfig -a | grep inet | grep -v '127.0.0.1' | 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)?

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% validated (X)HTML - Acorn / RISC OS / ARM, free software, YP17,
Championnat International des Jeux Mathématiques et Logiques, etc.
Work: CR INRIA - computer arithmetic / SPACES project at LORIA


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how do I find my IP address
  2004-06-14 11:57   ` Vincent Lefevre
@ 2004-06-14 12:23     ` James Devenish
  2004-06-14 13:18       ` Vincent Lefevre
  0 siblings, 1 reply; 7+ messages in thread
From: James Devenish @ 2004-06-14 12:23 UTC (permalink / raw)
  To: zsh-users

In message <20040614115736.GJ19941@ay.vinc17.org>
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 '127.0.0.1' | 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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how do I find my IP address
  2004-06-14 12:23     ` James Devenish
@ 2004-06-14 13:18       ` Vincent Lefevre
  0 siblings, 0 replies; 7+ messages in thread
From: Vincent Lefevre @ 2004-06-14 13:18 UTC (permalink / raw)
  To: zsh-users

On 2004-06-14 20:23:24 +0800, James Devenish wrote:
> 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.

I was asking for regular expressions (more powerful than patterns
used by filename generation).

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% validated (X)HTML - Acorn / RISC OS / ARM, free software, YP17,
Championnat International des Jeux Mathématiques et Logiques, etc.
Work: CR INRIA - computer arithmetic / SPACES project at LORIA


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-06-14 13:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-14  1:30 how do I find my IP address William Scott
2004-06-14  3:37 ` Jason Price
2004-06-14 10:58   ` Jussi Pakkanen
2004-06-14 11:57   ` Vincent Lefevre
2004-06-14 12:23     ` James Devenish
2004-06-14 13:18       ` Vincent Lefevre
2004-06-14  3:57 ` Timothy Luoma

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).