简体   繁体   English

无法使用Python脚本远程登录Cisco路由器

[英]Not able to telnet Cisco Router using Python script

I am trying to login to Cisco switch and run commands in it using python telnetlib script, after running the script it displays "password" in the output terminal for which i enter the switch password and then it hangs. 我试图登录到Cisco交换机并使用python telnetlib脚本在其中运行命令,运行该脚本后,它在输出终端中显示“密码”,为此我输入了交换机密码,然后挂起。

Note: there is no Username and Password.Enable password only given 注意:没有用户名和密码,仅提供密码

               import get pass
               import telnet lib
               Host='192.168.0.1'
               password=get pass.get pass()

               tn=telnet lib. Telnet(Host)

               tn.read_until('password:')
               tn.write(password +'\n') 
               tn.write('enable \n')
               tn.write('Cisco \n')
               tn.write('terminal length 0 \n')
               tn.write('sh version \n')
               tn.write('exit \n')
               print tn.read_all() 

i want to login and get show information from switch using python 我想使用python登录并从交换机获取显示信息

I am using PrettyGoodTerminal for python scripting cisco and juniper devices, works for me. 我正在将PrettyGoodTerminal用于python脚本cisco和juniper设备的Python,对我有用。 For running simple ios commands, you don!t event need pyton, but if you want to learn python, this is all what thee script you need 对于运行简单的ios命令,您不需要事件,但需要pyton,但是如果您想学习python,这就是您需要的全部脚本

result = Session.ExecCommand("show version")

For a simple tutorial look at this article 对于一个简单的教程,请看这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM