Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2019-06-25 03:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Is there a future for codeless software?



      Results (101 votes). Check out past polls.

      Notices?