Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#! /usr/local/bin/perl use strict; use Net::SNMP(qw(snmp_event_loop oid_lex_sort)); my ($session, $error) = Net::SNMP->session( -hostname => shift || 'localhost', -community => shift || 'public', -port => shift || 161 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } my $snmp; my %oid = ( TpFdbAddress => "1.3.6.1.2.1.17.4.3.1.1", TpFdbPort => "1.3.6.1.2.1.17.4.3.1.2", ); my $sysUpTime = '1.3.6.1.2.1.1.3.0'; my $sysDescr = '1.3.6.1.2.1.1.1.0'; my $sysObjectID = '1.3.6.1.2.1.1.2.0'; my $sysContact = '1.3.6.1.2.1.1.4.0'; my $sysName = '1.3.6.1.2.1.1.5.0'; my $sysLocation = '1.3.6.1.2.1.1.6.0'; my $sysServices = '1.3.6.1.2.1.1.7.0'; #my $macAddressOID = '1.3.6.1.2.1.17.4.3.1.1'; #my $macPortOID = '1.3.6.1.2.1.17.4.3.1.2'; print "\n\n"; ## =========== Get System Uptime =============== my $result = $session->get_request( -varbindlist => [$sysUpTime] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysUpTime for host '%s' is %s\n", $session->hostname, $result->{$sysUpTime} ); ## =========== Get System Description =============== my $result = $session->get_request( -varbindlist => [$sysDescr] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysDescr for host '%s' is %s\n", $session->hostname, $result->{$sysDescr} ); ## =========== Get System ObjectID =============== my $result = $session->get_request( -varbindlist => [$sysObjectID] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysObjectID for host '%s' is %s\n", $session->hostname, $result->{$sysObjectID} ); ## =========== Get System Contact =============== my $result = $session->get_request( -varbindlist => [$sysContact] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysContact for host '%s' is %s\n", $session->hostname, $result->{$sysContact} ); ## =========== Get System Name =============== my $result = $session->get_request( -varbindlist => [$sysName] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysName for host '%s' is %s\n", $session->hostname, $result->{$sysName} ); ## =========== Get System Location =============== my $result = $session->get_request( -varbindlist => [$sysLocation] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysLocation for host '%s' is %s\n", $session->hostname, $result->{$sysLocation} ); ## =========== Get System Services =============== my $result = $session->get_request( -varbindlist => [$sysServices] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysServices for host '%s' is %s\n", $session->hostname, $result->{$sysServices} ); ## =========== Get MAC Addresses =============== #my $result = $session->get_request( # -varbindlist => [$macAddressOID] #); # #if (!defined($result)) { # printf("ERROR: %s.\n", $session->error); # $session->close; # exit 1; #} #printf("sysServices for host '%s' is %s\n", # $session->hostname, $result->{$macAddressOID} #); ## =========== Get MAC Ports =============== #my $result = $session->get_request( # -varbindlist => [$macPortOID] #); #if (!defined($result)) { # printf("ERROR: %s.\n", $session->error); # $session->close; # exit 1; #} #printf("sysServices for host '%s' is %s\n", # $session->hostname, $result->{$macPortOID} #); ## ============= Added for loop to try and handle get_table() == for (keys %oid) { if (defined($snmp{response} = $snmp{session} -> get_table($oid{$ +_}))) { for (oid_lex_sort(keys(%{$snmp{response}}))) { print($snmp{response} -> {$_}, ",\n"); } } else { print($snmp{session} -> error(), ",\n"); } } } print "\n\n"; $session->close; exit 0;

In reply to Query a MAC address by jankovig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found