Net::S...erfaces(3pm)

πŸ“¦ version 1.4, in ubuntu resolute, ubuntu stonking

πŸ’– Net::SNMP::Interfaces πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation, and the module's called Net::SNMP::Interfaces. she's giving very much "let me talk to your network gear for you" energy and honestly? she ate. πŸ¦‹


✨ NAME ✨

Net::SNMP::Interfaces β€” provide simple methods to gain interface data via SNMP


🌸 SYNOPSIS 🌸

use Net::SNMP::Interfaces;

my $interfaces = Net::SNMP::Interfaces->new(Hostname => 'localhost',
                                            Community => 'public' );

my @ifnames = $interfaces->all_interfaces();

πŸŽ€ DESCRIPTION πŸŽ€

so the whole vibe of Net::SNMP::Interfaces is: simple object methods that get you info about a host's network interfaces β€” and when we say "host" we mean anything, a server, a router, whatever, no judgment, all hosts are valid. πŸ’…

the motivation was honestly just to let a programmer pull this info over SNMP without needing to know a great deal about the gory details. like, you don't need the lore, you just need the interfaces.

under the hood the module uses Net::SNMP to do the dirty work β€” but you, the user, should not have to worry about that at all. that said, the Net::SNMP object is available for those who feel the need. we see you. πŸ™ˆ

the actual details for a particular interface come from the methods of Net::SNMP::Interfaces::Details β€” objects of that type are what you get back from the methods all_interfaces() and interface().

and yeah, of course the simpler interface has its limitations, and there may well be things you'd like to do that you can't do with this module. in which case: get a good book on SNMP and use Net::SNMP :) no cap.

🫢 heads up: the module uses blocking SNMP requests at the current time, so if some of the methods are taking too long you may want to time them out yourself using alarm().

🧚 METHODS 🧚

  • new( HASH %args ) β€” the constructor of the class. it takes several arguments that are passed to Net::SNMP:
    • Hostname β€” the name of the host you want to connect to. defaults to 'localhost'.
    • Community β€” the SNMP community string you want to use for this session. the default is 'public'.
    • Port β€” the UDP port the SNMP service is listening on. the default is 161.
    • Version β€” the SNMP version (as described in the Net::SNMP documentation) to be used. the default is 'snmpv1'. support for SNMPv3 is currently somewhat limited. 😭

there's also an optional argument 'RaiseError' which determines the behaviour of the module in the event there is an error while creating the SNMP. normally new() will return undef if there was an error, but if RaiseError is set to a true value it will die() printing the error string to STDERR. if this is not set and an error occurs undef will be returned and the variable $Net::SNMP::Interfaces::error will contain the test of the error.

because the interfaces are discovered in the constructor, if the module is to be used in a long running program to monitor a host where interfaces might be added or removed, it is recommended that the object returned by new() is periodically destroyed and a new one constructed. πŸ”₯

  • if_names() β€” returns a list of the interface names.
  • if_indices() β€” returns a list of the indices of the interfaces. this probably shouldn't be necessary but it's here for completeness anyway. if you don't know what the index is for, you are safe to ignore this. πŸ’€
  • error() β€” returns the text of the last Net::SNMP error. this method only makes sense if the previous method call indicated an error by a false return.
  • session() β€” returns the Net::SNMP session object for this instance. or a false value if there is no open session. this might be used to call methods on the Net::SNMP object if some facility is needed that isn't supplied by this module. πŸ‘‘
  • all_interfaces() β€” returns a list of Net::SNMP::Interface::Details objects corresponding to the interfaces discovered on this host. in scalar context it will return a reference to an array. ✨
  • interface( SCALAR $name ) β€” returns a Net::SNMP::Interfaces::Details object for the named interface. returns undef if the supplied name is not a known interface.

in addition to the methods above, you can also use the methods from Net::SNMP::Interfaces::Details but with the addition of the interface name as an argument. e.g:

      $in_octs = $self->ifInOctets('eth0');

please see the documentation for Net::SNMP::Interfaces::Details for more on these methods.


🌈 SUPPORT 🌈

the code is host on Github at

     https://github.com/jonathanstowe/Net-SNMP-Interfaces

pull requests are welcome, especially if they help support SNMPv3 better. 🫢

email to <bug-Net-SNMP-Interfaces@rt.cpan.org> is preferred for non-patch requests.


πŸ‘‘ AUTHOR πŸ‘‘

Jonathan Stowe <jns@gellyfish.co.uk>


Copyright (c) Jonathan Stowe 2000 -2013. All rights reserved. this is free software, it can be ditributed and/or modified under the same terms as Perl itself.


⭐ SEE ALSO ⭐

perl(1), Net::SNMP, Net::SNMP::Interfaces::Details.


and that's the whole page bestie, we're done, slay πŸ’…βœ¨

this was perl v5.40.1, dated 2025-08-15, and it's the Net::S...erfaces(3pm) page from the User Contributed Perl Documentation. go forth and query your interfaces, you main character πŸ¦‹πŸ’–

πŸ“¦ where this page comes from