-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsnmpenum.pl
executable file
·135 lines (102 loc) · 3.11 KB
/
snmpenum.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#! /usr/bin/perl -w
#
# Simple Perl script to enumerate information on Machines that are running SNMP
#
# ----by filip waeytens 2003----
# ---- DA SCANIT CREW www.scanit.be ----
# filip.waeytens@hushmail.com
#
# Use it but don't abuse it. Read readme file.
# If you don't get all the output, the MIBS are probably not supported
# or the box only supports SNMPv1
#
# For Cisco: check this at
# http://www.cisco.com/public/sw-center/netmgmt/cmtk/mibs.shtml
#
# It's easy to add stuff, it's pretty straightforward.
# snmp stuff was taken from CPAN example :)
#
################################################################################
use strict;
use Fcntl;
use Net::SNMP qw(:snmp);
#declare global variables
my ($result,$v,$k);
my %request;
#usage
if (@ARGV!=3){
print "Usage: perl enum.pl <IP-address> <community> <configfile>\n\n";
exit 1;
}
#opening the config
my $config=$ARGV[2];
sysopen(CONFIG,$config, O_RDONLY)
or die "Couldn't open file for reading: $!\n";
#assigning the hash
while (<CONFIG>){
chomp $_;
my @system= split /\t+/,$_;
$request{$system[1]}=$system[2];
}
#establishing the snmp session
#V2 needed for snmpbulkrequests
my ($session, $error) = Net::SNMP->session(
-version => 'snmpv2c',
-nonblocking => 1,
-hostname => shift || '@ARGV[0]',
-community => shift || '@ARGV[1]',
);
#error message
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit 1;
}
#handling each request and printing request headers
while ( ($k,$v) = each %request ) {
print "\n\n"."-"x40 ."\n\t$k\n"."-"x40 ."\n\n";
my $result = $session->get_bulk_request(
-callback => [\&table_cb, {}],
-maxrepetitions => 10,
-varbindlist => [$v]
);
if (!defined($result)) {
printf("ERROR: %s.\n", $session->error);
$session->close;
exit 1;
}
snmp_dispatcher();
}
$session->close;
exit 0;
#subroutine for snmp getbulk stuff - taken from CPAN
sub table_cb
{
my ($session, $table) = @_;
if (!defined($session->var_bind_list)) {
printf("ERROR: %s\n", $session->error);
} else {
my $next;
foreach my $oid (oid_lex_sort(keys(%{$session->var_bind_list}))) {
if (!oid_base_match($v, $oid)) {
$next = undef;
last;
}
$next = $oid;
$table->{$oid} = $session->var_bind_list->{$oid};
}
if (defined($next)) {
$result = $session->get_bulk_request(
-callback => [\&table_cb, $table],
-maxrepetitions => 10,
-varbindlist => [$next]
);
if (!defined($result)) {
printf("ERROR: %s\n", $session->error);
}
} else {
foreach my $oid (oid_lex_sort(keys(%{$table}))) {
printf("%s\n",$table->{$oid});
}
}
}
}