python+Flask+paramiko+html实现本地windows和远程ssh linux命令行执行webterminal代码
代码语言:python
所属分类:其他
代码描述:python+Flask+paramiko+html实现本地windows和远程ssh linux命令行执行webterminal代码,在浏览器中就能操作本地电脑的命令行提示符,还能通过ssh远程连接linux进行命令输入,支持control+c终止命令的执行,流式输入,实时输出反馈。
代码标签: python Flask paramiko html 本地 windows 远程 ssh linux
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
import os
from flask import Flask, render_template_string, Response, jsonify, request
import subprocess
import paramiko
import psutil
from threading import Lock
app = Flask(__name__)
# 用于存储活动进程和 SSH 会话
active_processes = {}
active_ssh_sessions = {}
process_lock = Lock()
# HTML 模板(前端界面)
HTML_TEMPLATE = '''
<!DOCTYPE html>
<html>
<head>
<title>Web Terminal</title>
<style>
body { margin: 0; padding: 20px; background: #1e1e1e; }
#terminal-container {
width: 800px; height: 500px; background: #000; color: #0f0;
padding: 10px; font-family: 'Consolas', monospace; border-radius: 5px;
display: flex; flex-direction: column;
}
#terminal-output {
flex-grow: 1; overflow-y: auto; margin-bottom: 10px; white-space: pre-wrap;
}
#input-container { display: flex; align-items: center; padding: 5px 0; }
#current-path { color: #4CAF50; margin-right: 5px; white-space: nowrap; }
#command-input {
flex-grow: 1; background: transparent; color: #0f0; border: none;
outline: none; font-family: 'Consolas', monospace; font-size: 14px;
}
.c.........完整代码请登录后点击上方下载按钮下载查看















网友评论0