简体   繁体   English

无法执行命令到我的路由器python

[英]Can't execute commands to my router python

I am trying to make a project which in it i need to connect to the router from my code and recieve information from it -- > via python. 我正在尝试制作一个项目,其中我需要从我的代码连接到路由器并从中接收信息 - >通过python。

I have two routers : 1. TP-LINK TL-WR841N 2. D-LINK DAP-1360 我有两个路由器:1。TP-LINK TL-WR841N 2. D-LINK DAP-1360

also, after reserching a lot about the subject i have a code which should work: 此外,在研究了很多关于这个主题后,我有一个应该工作的代码:

import paramiko
import sys
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.0.1',port=22,username = 'admin',password = 'admin')
try:
    stdin, stdout, stderr = ssh.exec_command('ls -l')
    print
    output = stdout.readlines()
    print '\n'.join(output)
except:
    print sys.exc_info()[1]

My code succed to connect to each one of my routers(I inserted the ip and login information properly for each router I tried using) but failed to execute the commands im sending to him with the output: "channel closed." 我的代码成功连接到我的每个路由器(我为我尝试使用的每个路由器正确插入了ip和登录信息)但是无法执行我发送给他的命令输出:“channel closed”。

I know that its something on the router side that I should fix - but i dont know how to do it and I couldn't find any answers about it. 我知道我应该修复它在路由器端的东西 - 但我不知道该怎么做,我找不到任何关于它的答案。 Can someone try and help? 有人可以试着帮忙吗? thank you very much in advance. 非常感谢你提前。

如果没有像OpenWrt这样的自定义固件,您提到的路由器不支持ssh访问。

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

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