Running commands on cisco routers using python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SPJ

    Running commands on cisco routers using python

    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



  • Mike Driscoll

    #2
    Re: Running commands on cisco routers using python

    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

    Comment

    • Hartmut Goebel

      #3
      Re: Running commands on cisco routers using python

      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
      Hallo, mein Name ist Hartmut Goebel, ich bin Spezialist für Information-Security-Management mit starkem technischen Hintergrund. Zertifizierte Sicherheit und sinnvolles Sicherheits­management sind ele

      Comment

      • Floris Bruynooghe

        #4
        Re: Running commands on cisco routers using python

        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)Connect ion 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).

        Comment

        • James Harris

          #5
          Re: Running commands on cisco routers using python

          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.

          Comment

          Working...