Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Mar 2001 09:34:25 -0800 (PST)
From:      "Rodney W. Grimes" <freebsd@gndrsh.dnsmgr.net>
To:        mikel@ocsinternet.com (Mikel)
Cc:        johnny.dang@johnnydang.net (Johnny Dang), FREEBSD-IPFW@FreeBSD.ORG (FreeBSD IpFW)
Subject:   Re: Scripting with IPFW
Message-ID:  <200103271734.JAA91908@gndrsh.dnsmgr.net>
In-Reply-To: <3AC0A7B9.4E3DF96D@ocsinternet.com> from Mikel at "Mar 27, 2001 09:46:17 am"

next in thread | previous in thread | raw e-mail | index | archive | help
Please hard wrap you email at 72 char.

>     Thankfully Philip kindly pointed out the awk syntax 11 hours prior
> and I took a
> few minutes to rewrite the little play script to be exactly as you
> have presented
> here, only I didn't feel it was worth reposting wasted bw.

I saw Philip's post, after I had already replied... had I seen it
before I would not have bothered.

> What would
> have been nice
> for those of us who have only just started playing with awk; would
> have been to have
> some one suggest a code byte on how to have this thing automagickally
> grab the
> interface name from ifconfig.

That one is pretty tough, since you don't know which interface is
the inside, and which is the outside.  But if you just want a list
of the interfaces take a look at the output from ``ifconfig -l''.

There is no need to use awk on the output from ifconfig -a to get them.
For a sample of how to use ifconfig -l in a script take a look at
/etc/rc.network.


> "Rodney W. Grimes" wrote:
> 
> > > Hey man cool, hope you don't mind I had to try your script out and well I came
> > > up with this...thanks for sending back the code byte...
> > >
> > > #!/bin/sh
> > >
> > > oif=`ifconfig fxp0 |grep inet | head -1 | awk '{print $2}'`
> >
> > Obviosly people have totally forgotten how to program in the
> > language of awk, so instead use 2 other tools to do what could
> > be done much cleaner:
> >
> >         oif=`ifconfig fxp0 | awk '/inet/ {print $2; exit}'`
> >
> > Remeber, that grep X | awk 'foo' can almost always be rewritten
> > in a cleaner style as simply awk '/X/ foo'.
> >
> > > omask=`ifconfig fxp0 |grep inet | head -1 | awk '{print $4}'`
> > > iif=`ifconfig rl0 |grep inet | head -1 | awk '{print $2}'`
> > > imask=`ifconfig rl0 |grep inet | head -1 | awk '{print $4}'`
> >
> > The also seemed to have forgotten about doing common value
> > replacement by variables (fxp0 and rl0 should be replaced
> > by $something, which I would have called $iif, but that is
> > in use for something I would have called $iip).
> >
> > New code:
> > oif=fxp0
> > iif=rl0
> > oip=`ifconfig ${oif} | awk '/inet/ {print $2; exit}'`
> > omask=`ifconfig ${oif} | awk '/inet/ {print $4; exit}'`
> > iip=`ifconfig ${iif} | awk '/inet/ {print $2; exit}'`
> > imask=`ifconfig ${iif} | awk '/inet/ {print $4; exit}'`
> >
> > onet=`cidr -q ${oif} -h ${omask} | awk '/network/ {print $3}'`
> > inet=`cidr -q ${iif} -h ${imask} | awk '/network/ {print $3}'`
> >
> > >
> > > onet=`cidr -q ${oif} -h ${omask} | grep network | awk '{print $3}'`
> > > inet=`cidr -q ${iif} -h ${imask} | grep network | awk '{print $3}'`
> > >
> > > echo "onet=\"${onet}\""
> > > echo "oif=\"${oif}\""
> > > echo "omask=\"${omask}\""
> > > echo
> > > echo "inet=\"${inet}\""
> > > echo "iif=\"${iif}\""
> > > echo "imask=\"${imask}\""
> > >
> > >
> > > Cheers,
> > > Mikel
> > >
> > > PS: cidr is a neat little util found in /usr/ports/net/cidr
> > >
> > >
> > > Johnny Dang wrote:
> > >
> > > > Thanks you all (especially UNIX, SCANNER, Mikel, and Scott)... That is why
> > > > this FreeBSD is great... This line will do it (I can now base on this and
> > > > change to fix my need)...
> > > >
> > > > ifconfig de0 | grep "inet" | head -1 | awk '{print $2}'
> > > >
> > > > Thanks to you all... But why the orginal commands from Linux won't work on
> > > > FreeBSD?
> > > >
> > > > ifconfig de0 | grep "inet" | cut -d -f2 | cut -d " " -f1  ?
> > > >
> > > > Just for curiosity? Btw, I download the new RedHAT Wolverines and Mandrake
> > > > 8.0 and those GUI look like Lindows now. But my boss likes it !!!!!
> > > >
> > > > ++++++++++++++++++++++++++++++++++++++++++++++++++
> > > > "The instructions said to use Windows 98 or better,
> > > > so I installed FreeBSD...It is working now!..."
> > > > ++++++++++++++++++++++++++++++++++++++++++++++++++
> > > > Johnny Dang <Johnny.Dang@johnnydang.net>
> > > > Senior Network Engineer/MCSE + Internet
> > > >
> > > > To Unsubscribe: send mail to majordomo@FreeBSD.org
> > > > with "unsubscribe freebsd-ipfw" in the body of the message
> > >
> > >
> > > To Unsubscribe: send mail to majordomo@FreeBSD.org
> > > with "unsubscribe freebsd-ipfw" in the body of the message
> > >
> >
> > --
> > Rod Grimes - KD7CAX @ CN85sl - (RWG25)               rgrimes@gndrsh.dnsmgr.net
> >
> > To Unsubscribe: send mail to majordomo@FreeBSD.org
> > with "unsubscribe freebsd-ipfw" in the body of the message
> 
> 


-- 
Rod Grimes - KD7CAX @ CN85sl - (RWG25)               rgrimes@gndrsh.dnsmgr.net

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ipfw" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103271734.JAA91908>