#! /bin/bash
#set -x
#
# Define some variables
#
FILE="/tmp/bogon.list"
FILE2="/tmp/inter"
URL="http://www.cymru.com/Documents/bogon-bn.html#bn-non"
ETC="/usr/local/astium/etc/firewall/iana-reserved"

#
# Get the bogon list
#
lynx -dump $URL > $FILE
if [ $? -gt 0 ]
then
  exit 1
fi

COUNT=`wc -l $FILE | awk ' { print $1 } '`
if [ "$COUNT" -lt 10 ]
then
  exit 1
fi

fgrep -A $COUNT " Bit Notation Non-aggregated" $FILE | grep -v 192.168 > $FILE2

POSITION=`fgrep -n " Bit Notation Aggregated" $FILE2 | awk -F \: ' { print $1 } '`
POSITION=`expr $POSITION - 3`
fgrep -A $POSITION " Bit Notation Non-aggregated" $FILE2 | tail -n `expr $POSITION - 1` > $ETC

#
# Clean our mess
#
rm $FILE
rm $FILE2

