#!/usr/bin/perl -w
use strict;

use Net::Netmask;
use Cisco;
use Juniper;
use Extreme;
use config;

my %routers = config::routers;
my $forbidden_dir = config::forbidden_dir;

# close(STDOUT);

foreach my $router (keys %routers) {
	my $rtype = $routers{$router}{type};

	my $session = $rtype->login($routers{$router});

	my $lines = $rtype->show_direct_routes($session);
	open(OUTPUT, "> $forbidden_dir/$router") or die;
	foreach my $route (@$lines) {
		print "Type: $routers{$router}{type}\n";
		if ($routers{$router}{type} eq "Juniper") {
			print "Route: $route\n";
		}
		my $block = new Net::Netmask ($route);
		print OUTPUT $block->base()."\n";
		if ($block->bits() < 32) {
			print OUTPUT $block->broadcast()."\n";
		}
	}
	close(OUTPUT);
}

