#!/usr/local/bin/perl
# snmpbang - Request the system Description MIB from all the machines in a
#  given class C network.
#
# Requires a program called "snmpget" to do the real dirty work, though.
#
# Kees Cook 1997

$|=1;
$ip = $ARGV[0];
die "what class C ip address?" if (!$ip);
close(STDERR);
for ($i=1;$i<255;$i++) {
	if (fork==0) {
		select STDOUT;$|=1;
#		print "$i ";
	        open(IN,"echo $ip.$i: `snmpget $ip.$i public system.sysDescr.0` 2>/dev/null |");
		while (<IN>) {
			next if (/An error occurred, Quitting$/);
			next if (/^Mangled packet$/);
			next if (/^recvfrom: Connection refused$/);
			print;
		}
		close(IN);
		exit;
	}
	select(undef,undef,undef,0.2);
}
while (wait!=-1) {
	next;
}
