#! /bin/bash
# Copyright (c) 1997-now, NeoNova BV, The Netherlands. All rights Reserved.
#
# This software is the copyrighted work of NeoNova BV.
# Use of the software is subject to the general business terms and conditions of NeoNova BV
# and its related transaction documents like license sheets or other written notices.#
# Any reproduction or redistribution of the software not in accordance with the license terms
# is expressly prohibited by law, and may result in severe civil and criminally penalties.
# Violators will be prosecuted to the maximum extent possible.

#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

