#!/usr/bin/perl

# Logs on to Extreme Networks switches and rips arp tables via Telnet 
# Works on the assumption that all or most prompts will look the same.
# 
# Super Kludge, but I can't complain because it works.  
#
# -- Simon Carr, me@simoncarr.com

$username = "switch_user";
$passwd = "switch_pass"; # insecure... bah.
$prompt = '/55cc.*.>/';
$screens = "100"; @newlines = "\n"x$screens;

@switches = ("10.100.0.16"); # You can add switches here.  Format would be ("switch.ip","switch.ip","etc"); 

# This should be changed if the Net::Telnet package is installed properly
use Net::Telnet (); 
print $SELF; 

# start MAIN
foreach $switch (@switches) {	
	@lines = 0; 
	my ($identstring, @lines) = grab_lines_from_p00s($switch, $username, $passwd, $prompt); 
	
	chomp($identstring);
	$switch_delimiter_line = "-- Switch $identstring: $switch -- \n\n";
  
	push my @output,$switch_delimiter_line;
	push @output,@lines;
	push @output,"EOF\n";

	my $filename = "ARP.".$identstring.".".time().".txt";

	print $filename."\n"; 

	open(FH, ">$filename") or die "bee"; 
	print FH @output; 
	close FH;
}
# end MAIN

sub grab_lines_from_p00s($switch, $username, $passwd, $prompt) {

	my (@lines,@lines1,$line) = 0;

	$t = new Net::Telnet (Timeout => "10", Prompt => $prompt);
	$t->open($switch);
	$t->login($username, $passwd);
	
	@identity1 = $t->cmd(String => "show switch",
							  Prompt => $prompt); 
							  
	foreach my $ident (@identity1) {
		if($ident =~ /sysName/) { 
			@identstring1 = split(/:/,$ident);
		  	$identstring1[1] =~ (s/\t//g);
			$identstring = $identstring1[1]; # Messy, but it's the way I like it.
		}
		
	}
	
	@lines1 = $t->cmd(String => "show iparp",
							String => @newlines,	
							Prompt => $prompt); 

	foreach my $line (@lines1) {
		if($line !~ /Des/ and $line !~ /Press/) {
			push @lines,$line;
		}
	}
	
	return($identstring, @lines);
}

exit(0);
