python - 使用 Python Web 框架从远程 ssh 服务器向我的 html 页面显示消息
问题描述
我使用Python flask 和 paramiko从我的 html 表单在我的远程 ssh 服务器上执行命令。
它应该将消息显示回我的 html 文件:
(来自 ssh 服务器中执行的文件的结果)
欢迎任何想法或网站链接
谢谢你。
解决方案
您可以在函数中使用类似的东西。调用该函数后,将“输出”返回到 html。
import sys, paramiko
if len(sys.argv) < 4:
print "args missing"
sys.exit(1)
hostname = sys.argv[1]
password = sys.argv[2]
command = sys.argv[3]
username = "admin"
port = 22
try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.connect(hostname, port=port, username=username, password=password)
stdin, stdout, stderr = client.exec_command(command)
output = stdout.read(),
finally:
client.close()
推荐阅读
- php - PHP SQL数组在foreach循环中重复每个ID而不是一次一个ID
- javascript - 跨文件的打字稿全局变量
- android-studio - 我只输出整数但字符串不输出
- reactjs - 如何用进度条做一个步进器 Material-ui
- python - kivymd 的颜色定义问题
- docker - 通过 DirectAccess 连接到远程 docker 注册表
- python - Matplotlic Color by y-value Plot Draw Error
- c# - 主窗体 C# 的用户控件
- javascript - HTML JS - 通过 CSS 类禁用点击可能性
- python - tensorflow内存消耗不断增加