需求:通过网站url方式直接执行服务器的shell命令

实现:

1、安装依赖

pip3 install falsk

2、python脚本

[root@localhost tmp]# more falsh-index.py
from flask import Flask,render_template #Flask 、jinja2、pillow
import sqlite3
import subprocess app = Flask(__name__)
@app.route('/user/<name>')
def name(name):
print(name)
a = subprocess.getoutput(name) #执行shell命令
print(a)
return a # web 服务器
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=8888)
3、启动脚本

[root@localhost tmp]# python3 falsh-index.py
* Serving Flask app 'falsh-index' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://100.98.100.186:8888/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 123-927-491

  

  

  

 

python通过接口执行shell命令的更多相关文章

  1. Python ssh 远程执行shell命令

    工具 python paramiko 远程执行命令 import paramiko ssh = paramiko.SSHClient() key = paramiko.AutoAddPolicy() ...

  2. python中command执行shell命令脚本方法

    在Python中有一个模块commands也很容易做到以上的效果.看一下三个函数:1). commands.getstatusoutput(cmd)用os.popen()执行命令cmd, 然后返回两个 ...

  3. python之commands和subprocess入门介绍(可执行shell命令的模块)

    一.commands模块 1.介绍 当我们使用Python进行编码的时候,但是又想运行一些shell命令,去创建文件夹.移动文件等等操作时,我们可以使用一些Python库去执行shell命令. com ...

  4. 「Python」6种python中执行shell命令方法

    用Python调用Shell命令有如下几种方式: 第一种: os.system("The command you want"). 这个调用相当直接,且是同步进行的,程序需要阻塞并等 ...

  5. python中执行shell命令的几个方法小结

    原文 http://www.jb51.net/article/55327.htm 最近有个需求就是页面上执行shell命令,第一想到的就是os.system, os.system('cat /proc ...

  6. python的subprocess模块执行shell命令

    subprocess模块可以允许我们执行shell命令 一般来说,使用run()方法就可以满足大部分情况 使用run执行shell命令 In [5]: subprocess.run('echo &qu ...

  7. C++/Php/Python 语言执行shell命令

    编程中经常需要在程序中使用shell命令来简化程序,这里记录一下. 1. C++ 执行shell命令 #include <iostream> #include <string> ...

  8. python中执行shell命令行read结果

    +++++++++++++++++++++++++++++ python执行shell命令1 os.system 可以返回运行shell命令状态,同时会在终端输出运行结果 例如 ipython中运行如 ...

  9. python中执行shell命令的几个方法小结(转载)

    转载:http://www.jb51.net/article/55327.htm python中执行shell命令的几个方法小结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014- ...

  10. python(6)-执行shell命令

    可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen*          --废弃 popen2.*           --废弃 commands.* ...

随机推荐

  1. C语言两结构体之间的成员互换

    今天在写一个通讯录实现程序的时候,遇到个让我突然卡壳的问题,不知道怎么进行两个结构体之间的成员互换......结构体成员有"姓名","性别","年龄& ...

  2. [python] NetworkX实例

    文章目录 NetworkX实例 1. 基础Basic 2. 绘图Drawing 3. 图标Graph NetworkX实例 代码下载地址 NetworkX 2.4版本的通用示例性示例.本教程介绍了约定 ...

  3. [cocos2d-x]关于CC_CALLBACK

    CC_CALLBACK的代码 // new callbacks based on C++11 #define CC_CALLBACK_0(__selector__,__target__, ...) s ...

  4. 第 1 天|基于 AI 进行游戏开发:5 天创建一个农场游戏!

    欢迎使用 AI 进行游戏开发! 在本系列中,我们将使用各种 AI 工具,在 5 天内创建一个功能完备的农场游戏.到本系列结束时,你将了解到如何将多种 AI 工具整合到游戏开发流程中.本系列文章将向你展 ...

  5. springboot使用EasyExcel,导出数据到Excel表格,并且将Excel表中数据导入

    一.导出至Excel 1.导入依赖 导出方法需要使用到fastJson的依赖,这里也直接导入 点击查看代码 <!--阿里的easyexcel--> <dependency> & ...

  6. 阿里百秀后台管理项目笔记 ---- Day02

    来吧展示: step1: 动态获取用户头像信息 引入 jquery.js 文件 <script src="/static/assets/vendors/jquery/jquery.js ...

  7. DJI Flight Simulator 无人机模拟器 功能介绍与使用说明

    0 前言 无人机是当前非常火热的"相机设备",而大疆又是其中翘楚,功能丰富,可以说是一个将带着云台的智能手机放到了天空中.如果你有自己玩过旋翼无人机航模的话,可能会体会到大疆的另一 ...

  8. 洛谷 P3137 [USACO16FEB]Circular Barn S

    题目链接 本蒟蒻的第一篇题解,写得不好请指出,敬请谅解 题意: 有\(n\)头奶牛,分布在一些房间,某些房间可能有多头牛,要让这些牛按顺时针移动,求使每一个房间刚好有一个奶牛的最小花费 花费计算:如果 ...

  9. Linux 常用命令(测试于CentOS8版本)

    一.文件及文件夹操作 mkdir test #创建文件夹 默认在Home/test touch test.js #创建文件 默认Home/test.js touch test/test.js #创建文 ...

  10. ICSharpCode.SharpZipLib.Zip 解析时报错System.NotSupportedException: No data is available for encoding 936

    分析原因 利用ICSharpCode.SharpZipLib.Zip进行APK解析时,因为APK内编译的名称为中文,查询微软开发文档936为gb2312中文编码 微软开发文档地址https://doc ...