import from HEAD:
[freeradius.git] / dialup_admin / bin / snmpfinger
1 #!/usr/bin/perl
2 #
3 # This works with Net-SNMP and UCD-SNMP
4
5 $host=shift;
6 $comm=shift || 'public';
7 $type=shift || 'cisco';
8
9 $conf='/usr/local/dialup_admin/conf/admin.conf';
10 open CONF, "<$conf"
11         or die "Could not open configuration file\n";
12 while(<CONF>){
13         chomp;
14         ($key,$val)=(split /:\s*/,$_);
15         $snmp_type = $val if ($key eq 'general_snmp_type');
16         $snmpwalk = $val if ($key eq 'general_snmpwalk_command');
17 }
18 close CONF;
19
20 die "general_snmp_type directive is not set in admin.conf\n" if ($snmp_type eq '');
21 die "Could not find snmpwalk binary. Please make sure that the \$snmpwalk variable points to the right location\n" if (! -x $snmpwalk);
22
23 $snmpwalkcmd="$snmpwalk $host $comm" if ($snmp_type = 'ucd');
24 $snmpwalkcmd="$snmpwalk -v 1 -c $comm $host" if ($snmp_type = 'net');
25
26 if ($type eq 'cisco'){
27         $walk =`$snmpwalkcmd  .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2`;
28         if ($walk =~ /^$/){
29                 $walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.9.2.9.2.1.18`;
30                 $walk.=`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.9.10.19.1.3.1.1.3`;
31         }
32 }
33 elsif ($type eq 'lucent'){
34         $walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.529.10.4.1.12`;
35 }
36
37 while($walk=~/\"([\w\-]+?)\"/g){
38  $user=lc($1);
39  if($out) {
40   $out=$out.",'$user'";
41  }else{
42   $out="'$user'";
43  }
44 }
45 print "$out\n";