#!/usr/bin/perl $version = ' $Id: essenempee.pl,v 1.6 2002/09/25 16:19:07 torh Exp torh $ '; ## ## (c) th@bogus.net this program saw the light of day (night) on 5-sep-2002 00:31 ## ## This is an SNMP scanner/tester. Don't expect too much. It was written to ## do a specific job on a specific test. You'll probably need to edit it to suit ## your setup. ## $|=1; use Getopt::Long; GetOptions("h", "s=s" => \$start, "e=s" => \$end, "r=s" => \$range, "d=s" => \$snmppath, "m=s" => \$mibpath, "f=s" => \$inputfile); ## got more? ## @communities=("public","private","ILMI","system","snmppass","password","community", "cisco","hp","write","monitor","all","manager","agent", "admin","default","tivoli","openview","hpov","snmp","snmpd", "security","all private","rmon","rmon_admin","hp_admin", "northbay","panavue","passord","losenwort","HgxIUYQda", "test","testest","microsoft","billgates","gates","novell", "hidden","god","jesus","read-only","read only","world","secret", "toomanysecrets","internal","secure","bay","read","router", "secret","bogus","lame","pubsec","secpub","pubpri"); ## where we store net-snmp binaries ## if($snmppath) { $MAINPATH=$snmppath; } else { $MAINPATH=$ENV{"HOME"}."/net-snmp/apps"; } ## where we store net-snmp mibs ## if($mibpath) { $MIBPATH=$mibpath; } else { $MIBPATH=$ENV{"HOME"}."/net-snmp/mibs"; } if($opt_h) { print "$version (c) th\@bogus.net","\n"; print " -h: this information\n"; print " -r: first 3 octets of range to scan (oct1.oct2.oct3)\n"; print " -s: start IP (1)\n"; print " -e: end IP (254)\n"; print " -d: directory where net-snmp exists ($MAINPATH)\n"; print " -m: directory where mibs exist ($MIBPATH)\n"; print " -f: file containing IP's to scan (1 per line)\n"; print "This program relies on the 'ping' program, whose output differs\n"; print "on various architectures. At the time of writing, only Solaris\n"; print "and Linux are supported.\n"; exit(1); } if(!-x "$MAINPATH/snmpget") { print "ERROR: I can't seem to find the snmpget executable (-d).\n"; exit(1); } if(!-e $MIBPATH) { print "ERROR: I can't seem to find the net-snmp mibs (-m).\n"; exit(1); } if(!$inputfile) { ## crappy way of asking for IP's to scan ## unless ($range =~ /^\d+\.\d+\.\d+$/) { print "ERROR: I need the first 3 octets of network to scan (-r).\n"; exit(1); } unless (lc($ENV{"OSTYPE"}) =~ /solaris|linux/) { print "ERROR: Solaris and Linux only.\n"; exit(1); } if(!$start || $start > 255 || $start < 0) { print "WARNING: Bad start octet, using 1.\n"; $start=1; } if(!$end || $end > 255 || $end < 0) { print "WARNING: Bad end octet, using 254.\n"; $end=254; } } if(lc($ENV{"OSTYPE"}) =~ /solaris/) {$os="sun";} if(lc($ENV{"OSTYPE"}) =~ /linux/) {$os="lnx";} $timeout=1; if(!$inputfile) { print "ICMP scanning.."; for($i=$start;$i<($end+1);$i++) { if($os eq "sun") { $ping = `/usr/sbin/ping $range.$i $timeout 2>&1 > /dev/stdout`; if($ping =~ /(\d+\.\d+\.\d+\.\d+) is alive/) { $alive{$1}=1; print "!"; } else { print "."; } } if($os eq "lnx") { $ping = `/bin/ping -c 1 -w $timeout $range.$i 2>&1 > /dev/stdout`; if($ping =~ /64 bytes from (\d+\.\d+\.\d+\.\d+)/) { $alive{$1}=1; print "!"; } else { print "."; } } } } else { ## read ip's from $inputfile open(IN,$inputfile); while() { if(/^\s*(\d+\.\d+\.\d+\.\d+)\s*/) { $alive{$1}=1; } } close(IN); } ## scan each host that seemed to be alive ## foreach $ip (keys %alive) { next unless ($ip =~ /\d+\.\d+\.\d+\.\d+/); print "\nTrying SNMPGET against $ip: "; foreach $cstr (@communities) { @coms=Community($cstr); foreach $c (@coms) { $foo=$c; $cmd=`$MAINPATH/snmpget -r 0 -t $timeout -M $MIBPATH -c '$c' -v 1 $ip sysDescr.0 2>&1 > /dev/stdout`; chomp($cmd); if($cmd =~ /unknown object identifier/i) { print "FATAL: Are your mibs ok? ($cmd)\n"; exit(1); } if($cmd =~ /timeout/i) { print "."; $foo=""; next; } last if($cmd =~ /snmp/i); } last if($cmd =~ /snmp/i); } if($cmd =~ /snmp/i) { print "\n$foo ==> $cmd"; } } print "\n"; exit(1); ## generate some variations ## sub Community { my($str)=@_; my(@cms); push(@cms,$str); push(@cms,uc($str)); push(@cms,lc($str)); return(@cms); }