Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Cisco Router Query Script

by heldd (Initiate)
on Dec 19, 2002 at 16:07 UTC ( #221142=perlquestion: print w/replies, xml ) Need Help??

heldd has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone seen/writen a script that would import a file of ip addresses and return the hostname,ip,router type,and ios version to a text file?

Replies are listed 'Best First'.
Re: Cisco Router Query Script
by grinder (Bishop) on Dec 19, 2002 at 17:12 UTC

    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'
Re: Cisco Router Query Script
by dingus (Friar) on Dec 19, 2002 at 16:34 UTC
    There is a (free last time I looked) non perl proram that does this called SNMX. According to Google you can get it at http://www.snmpframeworks.com/Products/snmx.html

    There may be NET::SNMP based modules that do the same thing. Or I guess you could use Net::Telnet - assuming your routers have their telnet i/f enabled. But on the whole I'd recommend using a dedicated tool - this google query gives quite a few possibly relevant hits.

    Dingus


    Enter any 47-digit prime number to continue.

      Technically it is not freeware. From there site:

      The SNMX program may be downloaded from this site. We license SNMX for in-house and OEM applications with our "SNMX Rapid Development Environment". With this license, you can construct powerful SNMP management applications for your site, product, or end user. You receive:

      *SNIP*

      Note that, without a license, SNMX cannot be redistributed with any hardware or software systems, nor incorporated in any hardware or software platform. SNMX is not freeware, and SNMP Frameworks, Inc. rigorously enforces this rule!

      Reading their license it basically says you can use it free to help evaulate it. However, it looks interesting.

Re: Cisco Router Query Script (existing tested scripts)
by ybiC (Prior) on Dec 19, 2002 at 21:36 UTC
      Hiya brother heldd, First off, welcome to Perl Monks!

    Long Answer:   type "cisco" in the Search box at the upper left, and look through the different programs that turn up.   I can just about guaruntee you'll see one that does what you're asking for.

    Medium Answer:   go to my homenode, go to the #code section, and look through the different cisco-ey programs there.   I can just about guaruntee you'll see one the does what you're asking for.

    Short Answer:   go to this node "(code) Cisco sho ver" and click the "d/l code" button at the bottom.   You'll need to install the Net::Telnet::Cisco module, and I *think* you'll already have Term::ReadKey and Getopt::Long as part of the standard Perl distrubtion since 5.6 maybe.   I wrote that ditty almost two years ago, so looks kludgey to me now, but should work for you.   If you feel ambitious you could extract SNMP chunks from "(code) Poor Man's TACACS - automate CatOS and IOS password resets with Net::Telnet::Cisco and Net::SNMP" and have a more cleanly coded tool.

    Let me know if I can be of any further/other help.   8^)
      cheers,
      ybiC
        striving toward Perl Adept
        (it's pronounced "why-bick")
      ybiC, I have been playing with your scripts… and I have to say that they are quite impressive. I have the report working that I wanted and now I am faced with another dilemma. Getting a list of all of the ip addresses of the Cisco devices in my network!! I tried the cdp neighbor script and it works great up until it meets our Cisco IGX’s in our network. We have a layer 2 change at these devices from ATM to Frame and CDP will not cross it. Is there another way I can get a list of my Cisco devices? I thought about somehow pulling the eigrp neighbor list and using it for the seeds for the CDP script. Do you have any Ideas on how to modify the CDP script to do eigrp neighbor? I have around 3000 routers and switches and 164 people that can add devices to the network. In other words… things change every day. Thanks, Heldd

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://221142]
Approved by newrisedesigns
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-05-19 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?