#! /usr/bin/perl # # lg.pl Cisco Looking glass. To get this to work you need # to install Net::Telnet from the CPAN archives. # # Version: @(#)lg.pl 1.01 21-Oct-1997 miquels@cistron.nl # # Copyright (C) 1997 Cistron Internet Services B.V. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 dated June, 1991. use Net::Telnet 3.02; require './lg.cfg'; $| = 1; print <{Host}) eq '') { print "Unknown $VAR{'router'}\n"; exit(1); } $Port = $nick->{Port}; $Prompt = $nick->{Prompt}; $Login = $nick->{Login}; $Pass = $nick->{Pass}; $Timeout = $nick->{Timeout}; $IXPoint = $nick->{IXPoint}; # # Try to make it secure. # $addr = $VAR{'addr'}; $addr =~ s/[^\-a-zA-Z0-9. \t_^\*\$]//g; $addr =~ s/^\s+//; $addr =~ s/\s+$//; $addr = "212.36.96.251" if ($addr eq ''); print < $Company - $IXPoint - Looking Glass Results $Company
$IXPoint - Looking Glass Results


Query: $query EOF # # See what command we want to send. # if ($query eq 'bgp') { $cmd = "show ip bgp $addr"; } elsif ($query eq 'summary') { $cmd = "show ip bgp summary"; $addr = ''; } elsif ($query eq 'bgp dampening') { $cmd = "show ip bgp dampening"; $addr = ''; } elsif ($query eq 'environmental') { $cmd = "show environment"; $addr = ''; } elsif ($query eq 'bgp flap-statistics') { $cmd = "show ip bgp flap-statistics"; $addr = ''; } elsif ($query eq 'ping') { $cmd = "ping $addr"; } elsif ($query eq 'trace') { $cmd = "trace $addr"; } else { $cmd = "show clock"; $addr = ''; } print "
Addr: $addr\n" if ($addr ne ''); print "

\n";

$ses = new Net::Telnet  (Host => $Host,
                        Port => $Port,
                        Prompt => "/$Prompt/i",
			Timeout => $Timeout);

if (!$ses) {
	print "lg.pl: connect to router $Host failed\n";
	exit(1);
}

#
#	Login and turn off `more' style paging.
#
if ($Login ne '' and $Pass ne '') {
	$ses->login($Login, $Pass);
} elsif ($Login eq '' and $Pass ne '') {
	$ses->waitfor('/password[: ]*$/i');
	$ses->cmd($Pass);
} else {
	$ses->waitfor("/$Prompt/i");
}
$ses->cmd("term len 0");

#
#	Send command.
#
$ses->print($cmd);

#
#	Print the output up to the next prompt.
#
$first = 1;
$ses->input_record_separator("\xff");

while (($junk, $_) = $ses->waitfor("/(^.*\n|$Prompt)/i")) {
	if ($first) {
		$first = 0;
		next;
	}
	last if (/$Prompt/);
	print;
}
$ses->input_record_separator("\n");
# $ses->cmd("exit");
$ses->close;

print <


Return to the first page.

Please e-mail questions or comments to $Email.

EOF 0;