473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Running commands on cisco routers using python

SPJ
Is it possible to run specific commands on cisco router using Python?
I have to run command "show access-list" on few hundred cisco routers and get the dump into a file. Please let me know if it is feasible and the best way to achieve this.

Thanks,
SPJ

Jun 27 '08 #1
4 7244
On May 19, 10:18 am, SPJ <mail2...@yahoo.comwrote:
Is it possible to run specific commands on cisco router using Python?
I have to run command "show access-list" on few hundred cisco routers and get the dump into a file. Please let me know if it is feasible and the best way to achieve this.

Thanks,
SPJ
I think it depends on how you're connecting to the routers.
Theoretically, you should be able to use Python's socket or ssh
modules to connect to them, send commands and capture the output.

Just experiment with one or two routers until you get it.

Mike
Jun 27 '08 #2
Mike Driscoll schrieb:
On May 19, 10:18 am, SPJ <mail2...@yahoo.comwrote:
>Is it possible to run specific commands on cisco router using Python?
I have to run command "show access-list" on few hundred cisco routers and get the dump into a file. Please let me know if it is feasible and the best way to achieve this.

Thanks,
SPJ

I think it depends on how you're connecting to the routers.
Theoretically, you should be able to use Python's socket or ssh
modules to connect to them, send commands and capture the output.
I've implemented a toolset for login into cisco components, issueing
commands and fetchign the results. Works like a charm.

Keypoint here is using pexpect for interacting with SSH.

--
Schönen Gruß - Regards
Hartmut Goebel

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen
http://www.goebel-consult.de
Jun 27 '08 #3
On May 19, 4:18*pm, SPJ <mail2...@yahoo.comwrote:
Is it possible to run specific commands on cisco router using Python?
I have to run command "show access-list" on few hundred cisco routers
and get the dump into a file. Please let me know if it is feasible and
the best way to achieve this.
There's no way I'd think about doing this in python. The best tool
for the task is just shell IMHO:

flub@signy:~$ ssh mercury show access-lists
Welcome to mercury
root@mercury's password:

Standard IP access list 1
10 permit any (265350 matches)
Standard IP access list 23
10 permit 192.168.2.0, wildcard bits 0.0.0.255 (2 matches)
Extended IP access list 100
10 deny ip any 192.168.0.0 0.0.255.255 log-input (8576 matches)
20 permit ip any any (743438 matches)Connection to mercury closed
by remote host.
flub@signy:~$

You could plug in expect to solve the password thing. Search for "ssh
expect" for that (and ignore suggestions about public keys, I haven't
found yet how to use those on cisco).
Jun 27 '08 #4
On 19 May, 16:18, SPJ <mail2...@yahoo.comwrote:
Is it possible to run specific commands on cisco router using Python?
I have to run command "show access-list" on few hundred cisco routers and get the dump into a file. Please let me know if it is feasible and the best way to achieve this.
Can you access the routers with telnet or do you need to use ssh? I've
written loads of Python to access Cisco routers using a wrapper around
the standard telnetlib. Telnetlib supplies an excellent expect
function which makes this work.

It is telnet, though. If I had to use ssh I would probably add it
under the same wrapper so that higher level code could work unchanged.
There may be a way to route the telnet interractions through openssh
or similar externally but I haven't tried that.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
0
by: NewsReader | last post by:
Hello, I have been looking around the net for a script to help me connect to and help gather information from Cisco routers/switches. I have pieced together a couple of different scripts from...
2
usafshah
by: usafshah | last post by:
well i didn't find any section related to cisco routers. i think it will be more helpful for ppl like me if you included cisco routers section in this community also. Thanks
1
by: wcl152010 | last post by:
Hi, I have a general doubt here regarding of monitoring different model of CISCO Switches and Routers. I am new in SNMP, I tried to search for CISCO related mib file in the net and i got at...
3
by: Shahjehan | last post by:
I have to configure Cisco Router and get their sh-run on my PC using python. Is this possible? Do cisco routers provide provision of accessing them through scripting?
0
by: deviao | last post by:
Hello all. I am just about to start learning Python as a friend reccomended it as a very useful and flexible language. I was just wondering if Python has the ability to connect to a Cisco...
0
sicarie
by: sicarie | last post by:
http://www.networkworld.com/news/2008/051408-hacker-writes-rootkit-for-ciscos.html So the POC is out there and Cisco has acknowledged that it is real - is everyone keeping up to date with their...
0
by: abhi | last post by:
SAN JOSE, Calif. — Forget the switches and routers that built Cisco Systems into a giant, albeit somewhat boring, company at the core of the Internet. These days, the company is peddling e-mail...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.