Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Getting the hostname is easy enough, get gethostbyname. The router type and IOS version are going to be more tricky.

The safest way would be to set up your SNMP environment correctly, and then ask the router to send you its 'system.sysDescr.0' OID. There are loads of ways to do this with Perl, but I don't know which way would suit you. Start by looking at Net::SNMP.

Another way would be to open up a telnet session with the router and ask it to tell you.

When I used to play with Cisco routers I was quite happy with Net::Telnet::Cisco. It's pretty simple to use if you're familiar with Net::Telnet or Expect. In a nutshell, if you can craft a command (e.g.: get version, you can get what you are looking for.

Shamelessly stealing from the documentation, an example of how you would go about this would look like:

use Net::Telnet::Cisco; my $session = Net::Telnet::Cisco->new(Host => '123.123.123.123'); $session->login('login', 'password'); # Execute a command my @output = $session->cmd('show version'); print @output; # Enable mode if ($session->enable("enable_password") ) { @output = $session->cmd('show privilege'); print "My privileges: @output\n"; } else { warn "Can't enable: " . $session->errmsg; } $session->close;

This approach is of course only as safe as your network. I would hope you use an account/password pair that has no privileges to change the routers' configurations.


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: Cisco Router Query Script by grinder
in thread Cisco Router Query Script by heldd

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 chanting in the Monastery: (3)
As of 2024-04-25 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found