extract IP address and feed it into a command

Tom Smith tom at openadventures.org
Mon Apr 28 15:36:23 PDT 2003


This is taken from a Linux firewall script I use to determine a Dynamic 
IP address. In this case, $IFCONFIG, $EXTIF, and $AWK are defined as 
variables. For reference, IFCONFIG=/sbin/ifconfig, EXTIF=eth0, AWK=/bin/awk.

EXTIP="`$IFCONFIG $EXTIF | $AWK 
$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"

I didn't write this script so I don't fully understand what it's doing 
but maybe it'll lead you in the right direction.

DJ Boris wrote:

>hi there,
>
>I am running fBSD 4.7 release.
>
>I need to extract my IP address which is dynamically assigned by my ISP and
>feed it into a serialmail command
>
>"maildirsmtp ~alias/pppdir alias-ppp- 1.2.3.4 `hostname` "
>
>which is executed from my ppp.linkup.
>
>I have to replace hostname with my dynamic IP.
>
>I know that my IP always starts with zzz.zzz and if I run
>
>"ifconfig | grep zzz.zzz"
>
>I get
>
>inet zzz.zzz.xxx.xxx --> yyy.yyy.yyy.yyy netmask nnnnnnnnnn
>
>Is there a command or something else that I can use in order to get only the
>IP starting with zzz.zzz up to the first space and how do I feed it into the
>above command?
>
>thanx
>dj boris
>
>
>_______________________________________________
>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