Running commands on cisco routers using python

S

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
 
M

Mike Driscoll

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
 
H

Hartmut Goebel

Mike said:
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
 
F

Floris Bruynooghe

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).
 
J

James Harris

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top