从我的网站表单向远程ssh服务器发送命令 [英] Send commands to a remote ssh server from my website form

查看:97
本文介绍了从我的网站表单向远程ssh服务器发送命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个用户可以填写表格的网站,

I want to create a website that users can fill a form,

然后将这些参数发送到远程ssh服务器以发出python脚本.

and then I send those parameters to a remote ssh server to issue a python script.

例如,在我的网页中,表单包含输入文本,para1,para2,para3等.

Example, in my webpage, the form contains input text, para1, para2, para3, etc..

用户单击提交"后,它应该能够将命令发送到远程ssh服务器终端"python para1,para2,para3,.....".

After the user clicks submit, it should be able to send a command to remote ssh server terminal "python para1, para2, para3,....."

我需要什么样的技术来解决这个问题?

What kind of technique that I need to solve this problem??

谢谢.

推荐答案

您可以使用Flask Framework创建Web应用程序,然后使用 Paramiko模块将Python脚本与SSH服务器连接并执行 来自本地计算机的命令.您的python脚本将充当SSH 客户.

You can create a Web application using Flask Framework and then use the Paramiko module to connect Python script with SSH Server and execute commands from the local machine. Your python script will act as an SSH client.

查看此链接,其中显示了使用Python和Flask Framework创建Web应用程序的步骤: https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972

Check out this link which shows steps to create a web application using Python and Flask Framework: https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972

Web应用程序示例:
对于您的简单表格,您可以更新主页和注册页面以获取 形成参数,并使用这些参数将命令传递给SSH服务器.

Web application Example:
For you simple form, you can update home page and sign up page to get form parameters and use those parameters to pass commands to the SSH server.

请在下面找到Paramiko的链接和一个显示示例的链接.设置Paramiko真的很容易.

Please find below the link for Paramiko and one link showing examples. It is really easy to set up the Paramiko.

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)
    print stdout.read(),

finally:
    client.close()

在这里,主机名将是SSH服务器,而用户名和密码将是您通常用于连接SSH服务器的用户名.

Here, the hostname will be the SSH server and the username and password will be the one which you usually use to connect to the SSH server.

Paramiko- http://docs.paramiko.org/en/stable/
示例- https://gist.github.com/mlafeldt/841944

Paramiko - http://docs.paramiko.org/en/stable/
Example - https://gist.github.com/mlafeldt/841944

这篇关于从我的网站表单向远程ssh服务器发送命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆