Python2.6 と関連パッケージをインストールします。
# yum -y install python26 --enablerepo=epel # yum -y install python26* --enablerepo=epel
Python2.6 を実行してみます。
# python26 Python 2.6.8 (unknown, Nov 7 2012, 14:47:45) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Exscript をダウンロードします。
# wget --no-check-certificate -O knipknap-exscript-v2.1-388-g65e7e55.tar.gz https://github.com/knipknap/exscript/tarball/master
Exscript をインストールします。
# easy_install-2.6 knipknap-exscript-v2.1-388-g65e7e55.tar.gz
下記の script(cisco.py) を実行してみます。
from Exscript.util.interact import read_login from Exscript.protocols import SSH2 account = read_login() conn = SSH2() conn.connect('192.168.1.1') conn.login(account) conn.execute('terminal length 0') conn.execute('show version') print conn.response conn.send('exit\r') conn.close()
C181X へアクセスし show version を取得する事ができました。
# python26 cisco.py Please enter your user name [root]: cisco Please enter your password: show version Cisco IOS Software, C181X Software (C181X-ADVENTERPRISEK9-M), Version 15.1(3)T4, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc. Compiled Thu 24-May-12 07:09 by prod_rel_team ROM: System Bootstrap, Version 12.3(8r)YH9, RELEASE SOFTWARE (fc1) myrouter uptime is 4 weeks, 17 hours, 21 minutes System returned to ROM by reload at 00:36:43 JST Sat Mar 9 2013 System image file is "flash:c181x-adventerprisek9-mz.151-3.T4.bin" Last reload type: Normal Reload This product contains cryptographic features and is subject to United States and local country laws governing import, export, transfer and use. Delivery of Cisco cryptographic products does not imply third-party authority to import, export, distribute or use encryption. Importers, exporters, distributors and users are responsible for compliance with U.S. and local country laws. By using this product you agree to comply with applicable laws and regulations. If you are unable to comply with U.S. and local laws, return this product immediately. A summary of U.S. laws governing Cisco cryptographic products may be found at: http://www.cisco.com/wwl/export/crypto/tool/stqrg.html If you require further assistance please contact us by sending email to export@cisco.com. Cisco 1812-J (MPC8500) processor (revision 0x400) with 354304K/38912K bytes of memory. Processor board ID FHKxxxxxxSN, with hardware revision 0000 10 FastEthernet interfaces 1 ISDN Basic Rate interface 1 Virtual Private Network (VPN) Module 62720K bytes of ATA CompactFlash (Read/Write) License Info: License UDI: ------------------------------------------------- Device# PID SN ------------------------------------------------- *0 CISCO1812-J/K9 FHKxxxxxxSN Configuration register is 0x2102
(参考)
https://github.com/knipknap/exscript/issues/15
http://stackoverflow.com/questions/7140817/python-ssh-into-cisco-device-and-run-show-commands