#!/usr/bin/perl

use SNMP;
use Data::Dumper;

$SNMP::use_sprint_value = 1;

my $host = "localhost";
my $community="public";

$sess = new SNMP::Session(
	'DestHost'	=> $host,
	'Community'	=> $community,
	'Version'	=>  1
	);

die "cannot create session: ${SNMP::ErrorStr}\n" unless defined $sess;


my $response = $sess->gettable('ifTable');	# $response is a reference to hash
print "size of response is " . keys(%$response) . "\n";

@keys = keys(%$response);

print "keys are :";
foreach my $k (@keys) {
	print "$k ";
}
print "\n";

##================== print values??

my $eth0 = %{$response->{1}};		# weird use of $; this should be another hash.
my @eth0keys = keys %{$response->{1}};
print "eth0 keys: " . @eth0keys . "\n";
foreach my $k (@eth0keys) {
	print "$k ";
}
print "\n";

print("========================\n");

# from www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/hash/
# goal: print everything in a two-level hash *reference*

for my $k1 ( sort keys %$response ) {
    print "key: $k1\n";
    for my $k2 ( keys %{$response->{ $k1 }} ) {
        print "    $k2 $response->{ $k1 }{ $k2 }\n";
    }
}

#=============================

# print Dumper(%$response);


	
