473,289 Members | 2,091 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,289 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 7240
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.