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



  • 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, details, 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, summary, 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.