Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jan 2005 22:22:47 -0600
From:      Eric F Crist <ecrist@secure-computing.net>
To:        Timothy Luoma <lists@tntluoma.com>
Cc:        FreeBSD-Questions Questions <freebsd-questions@freebsd.org>
Subject:   Re: my lame attempt at a shell script...
Message-ID:  <49F924A2-5E08-11D9-B56F-000D9333E43C@secure-computing.net>
In-Reply-To: <491556AE-5DF7-11D9-89A5-000D93AD26C8@tntluoma.com>
References:  <06DDB71C-5DB4-11D9-B56F-000D9333E43C@secure-computing.net> <15416223037.20050103193803@hexren.net> <6074EB8D-5DC6-11D9-89A5-000D93AD26C8@tntluoma.com> <F0BE3E23-5DC8-11D9-B56F-000D9333E43C@secure-computing.net> <41D9BA53.4060105@locolomo.org> <2DF07A46-5DD2-11D9-89A5-000D93AD26C8@tntluoma.com> <D7D0CFB3-5DD5-11D9-B56F-000D9333E43C@secure-computing.net> <3E8DD18E8557227C2A3C8E5A@utd49554.utdallas.edu> <AB283AB4-5DD9-11D9-B56F-000D9333E43C@secure-computing.net> <7C6BEBEDE2DB4AC7E55D6843@utd49554.utdallas.edu> <3D1AE682-5DDF-11D9-B56F-000D9333E43C@secure-computing.net> <491556AE-5DF7-11D9-89A5-000D93AD26C8@tntluoma.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail-16--196167366
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed


On Jan 3, 2005, at 8:21 PM, Timothy Luoma wrote:

>
> On Jan 3, 2005, at 6:28 PM, Eric F Crist wrote:
>
>> A couple more questions, then I'm done. Promise.
>>
>> I need to verify whether or not there is an entry for 
>> grog_firewall_oif
>> and grog_firewall_iif in /etc/rc.conf.  If not, I want to exit with an
>> error.
>
> You want to check for either "grog_firewall_oif" or 
> "grog_firewall_iif" in /etc/rc.conf
>
> egrep -v "^#" /etc/rc.conf |\
> egrep -q "grog_firewall_oif | grog_firewall_iif" || (echo "$0" ; exit 
> 1)
>
> The first line says "skips the comment lines" (the ones that begin 
> with #)
>


What does the second line do?  I tried, apparently, to accomplish the 
same
thing with some different syntax, yet unsuccessfully.


>> Also, a little more advanced, I need to pull information from an
>> ifconfig output.  I need to pull network numbers for both the internal
>> interface, as well as external interface.  For example,
>>
>> vr0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
>>          inet 192.168.1.5 netmask 0xffffff00 broadcast 192.168.1.255
>>          inet6 fe80::20e:a6ff:feb9:2d3d%vr0 prefixlen 64 scopeid 0x3
>>          ether 00:0e:a6:b9:2d:3d
>>          media: Ethernet autoselect (100baseTX <full-duplex>)
>>          status: active
>>
>> I don't actually need my own address, I need to be able to figure out
>> that the system, based on the above output, is on the 192.168.1.0/24
>> network.  This will be input into my firewall rulesets.
>>
>> I imagine that there's a util or command around that can do this, or I
>> can code out the math, but there's got to be an easier way.
>
> How much can you assume?  Will you know the interface?  If so it's 
> fairly easy
>
> ifconfig vr0  |\
> 	tr '\012' ' ' |\
> 	 sed 's#.*inet ##; s# netmask.*##'
>
> roughly translated:
> line 1: give me the information for vr0 only
> line 2: replace the end of line (\012) and replace them with a space
> line 3: delete everything from the beginning of the line up to "inet " 
> and then delete everything from " netmask" to the end of the line
>
> Put it into a variable
>
> MY_IP=`ifconfig vr0  |\
> 	tr '\012' ' ' |\
> 	 sed 's#.*inet ##; s# netmask.*##'`
>
> TjL

I can assume everything, since grog_firewall_oif *should* be a value 
such as above.  On my system, grog_firewall_oif will be ath0.  This 
isn't assumed, but rather defined for me.  I would write the above line 
as follows (please verify syntax):

ifconfig $grog_firewall_oif |\
	tr '\012' ' ' |\
	sed 's#.*inet ##; s# netmask.*##'

oif_ip=`ifconfig $grog_firewall_oif |\
	tr '\012' ' ' |\
	sed 's#.*inet ##; s# netmask.*##'`

This is a lot of help, however, if you read:

>> I don't actually need my own address, I need to be able to figure out
>> that the system, based on the above output, is on the 192.168.1.0/24
>> network.

I need my NETWORK address, in this case 192.168.1.0 (with netmask), 
which would be 192.168.1.0/24

Thanks.
_______________________________________________________
Eric F Crist                  "I am so smart, S.M.R.T!"
Secure Computing Networks              -Homer J Simpson

--Apple-Mail-16--196167366
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iEYEARECAAYFAkHaGhgACgkQRAAY9knOW+ppfQCeMfx2z1KKQnI1vwZ2HJF1i3NJ
tzYAmgJS24XOyY8DUNb+QPessYjoTqVX
=Ta04
-----END PGP SIGNATURE-----

--Apple-Mail-16--196167366--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49F924A2-5E08-11D9-B56F-000D9333E43C>