Bill Brooks wrote:
> 
> On Mon, 22 Mar 1999, Tuan Hoang wrote:
> 
> > What is the best way to get the ip address from
> > a device, such as ppp0, ppp1, eth0, eth1, etc...?
> >
> > Are there a few ways?  Easiest?  Pro's & Con's?
> 
> I'm trying to do the same thing. What I want to do, is in a shell script
> that I'll eventually add to /etc/rc.d/init.d is to get the IP address of
> the local machine. Now, of course the machine can have multiple
> interfaces, so just looking at the output of ifconfig doesn't help a lot.
> 

>From Linux Network Toolkit, by Paul G. Sery, IDG Books.  ISBN 0-7645-3146-8

# To obtain the dynamic PPP IP address, the output of ifconfig is piped to
# grep which strips out all the lines except the one containing the address
# and pipes it to awk which strips out the 2nd field containing the address.
# The final step has sed eliminate the text string "addr:" leaving just the
# IP address. There is probably a simpler way to do this but it works for me.

ISP_IP=`ifconfig ppp0 |grep 'inet addr'| awk '{print $2}'|sed -e "s/addr\://"`
echo $ISP_IP


--
Chuck Gadd
Director of Software Development, Cyber FX Communications
e-mail:[EMAIL PROTECTED]  http://www.cfxc.com
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to