[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Is there a utility to get IP address from interface?



On Wed, Jun 09, 2004 at 11:08:12AM +1000, James Sinnamon wrote:
> Dear debian users,
> 
> Is there a utility to simply return the IP address of an interface, say
> eth1 or ppp0?  I need something that works like:
> 
> $ netutil eth0
> 144.133.251.117
> 
> ... or is it necessary to use ifconfig something like as follows:
> 
> $ ifconfig eth0 | sed ' ... ' | cut '....' | awk '...'  | .... etc
> 144.133.251.117

ipmasq package have command for it (but installing ipmasq have side
effect of setting your system as gateway machine.)

Here is "/usr/sbin/ipofif" command:
---------------------------------------x8
#!/bin/sh
#
# ipofif        Determines the IP address of the interface given on the
#               commandline

export LC_ALL="C"
export LANG="C"
export LANGUAGE="C"

( /sbin/ifconfig $1 | sed -n -e'/inet addr:/s/^.*inet addr:\([0-9.]*\).*$/\1/p' ) 2>/dev/null
true
---------------------------------------x8

You may do "apt-get install -d ipmasq" and peek into package with "mc" :)
There are few other script you may want to use :)

"sed" is much lighter than "perl" and available even when /usr is not
mounted yet.

Osamu



Reply to: