栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

自制一款远程控制软件——VeryControl

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

文章目录
  • 前言
  • 软件下载
  • 代码展示
    • H T M L HTML HTML 前端部分
      • 1.客户端主页
      • 2.拍照、截图
    • P y t h o n Python Python 后端部分
      • 1. / m a i n . p y /main.py /main.py
      • 2. / V e r y C o n t r o l / u r l s . p y /VeryControl/urls.py /VeryControl/urls.py
  • 最后

前言

前排提醒:这篇文章有点儿长,如果直接想看效果可以来此下载,代码看看就行了。

                                                                         _..._       .-'''-.                                    .-'''-.
                                                                      .-'_..._''.   '   _                                     '   _      .---.
 .----.     .----.   __.....__                                      .' .'      './   /` '.       _..._                     /   /` '.    |   |
         /    /.-''         '.         .-.          .-           / .'          .   |       '  .'     '.                  .   |       ' |   |
   '   '. /'   //     .-''"'-.  `. .-,.--.         / /          . '            |   '      |  '.   .-.   .     .|  .-,.--. |   '      |  '|   |
   |    |'    //     /________   |  .-. |       / /           | |                     / / |  '   '  |   .' |_ |  .-. |         / / |   |
   |    ||    ||                  || |  | |      / /            | |             `.   ` ..' /  |  |   |  | .'     || |  | | `.   ` ..' /  |   |
   '.   `'   .'    .-------------'| |  | |     / /             . '                '-...-'`   |  |   |  |'--.  .-'| |  | |    '-...-'`   |   |
            /      '-.____...---.| |  '-     `  /                '.          .              |  |   |  |   |  |  | |  '-                |   |
           /    `.             .' | |           /                 '. `._____.-'/              |  |   |  |   |  |  | |                    |   |
      '----'       `''-...... -'   | |         / /                    `-.______ /               |  |   |  |   |  '.'| |                    '---'
                                   |_|     |`-' /                              `                |  |   |  |   |   / |_|
                                            '..'                                                '--'   '--'   `'-'

VeryControl 软件的 Logo

我最近多少有点儿闲得慌,前两天出去玩儿了一圈,路上就一直盘算着这事儿,前两天做了个雏形,今天完善好了,分享给大家一起看着玩儿。

这个程序感觉还凑合,制作了一个网页端。虽然设计不咋样吧(我是初学者),但是至少能在手机、电脑等各种设备上成功访问并进行远程命令执行。

用到的语言是 P y t h o n Python Python 和 H T M L HTML HTML,使用了 D j a n g o Django Django 框架,及一些其他的小功能。

软件截图:

软件下载

建议阅读里面的注意事项,很重要。
可能CSDN资源还没有通过审核,可以使用下面的仓库看程序。

软件下载地址:https://download.csdn.net/download/PanDaoxi2020/86265805
有一个开源的地址:https://pandaoxi.coding.net/public/pandaoxi/Projects/git/files/master/Very_Control

代码展示

让我们一起来看看这个小项目的源代码叭~

H T M L HTML HTML 前端部分

H T M L HTML HTML 部分主要是客户端的一些东西,直接在网页上访问,并传回相应的内容给后端 A P I API API 。

1.客户端主页

最基本的内容,可以直接在主页填写命令的表单,然后 P O S T POST POST 给后端的 A P I API API /run。

{ c o m m a n d = 普通执行命令 e c h o = 输入命令,并返回输出内容 c o d e = 执行批处理命令 r u n f = 运行应用程序(需要应用程序提交工具) begin{cases} & text command=普通执行命令 \ & text echo=输入命令,并返回输出内容 \ & text code=执行批处理命令 \ & text runf=运行应用程序(需要应用程序提交工具) \ end{cases} ⎩ ⎨ ⎧​​command=普通执行命令echo=输入命令,并返回输出内容code=执行批处理命令runf=运行应用程序(需要应用程序提交工具)​


Very Control



Very Control 多对一远程控制平台

输入命令:

带有回显的命令:

提交批处理文件的源代码:

或者使用应用程序提交工具



当前软件信息:

版本: 1.3.0.0 [2022-7-22 Update]

开发者:PanDaoxi

开源地址:点击这里去访问!

开发者邮箱(欢迎意见反馈和技术支持):
自制一款远程控制软件——VeryControl


其他功能:截取屏幕 查看被控制者信息 捕获摄像头 发送消息 阅读官方通知

2.拍照、截图

这两个功能的页面基本相同。

摄像头捕获

摄像头捕获


该功能可能会比较卡顿;如果不能正常显示出摄像头图像,可能是因为被控制设备的摄像头无法访问。



回到主页 重新拍照
Screen Shot
截图


回到主页 重新截图
P y t h o n Python Python 后端部分

目录树:

D:.
│  db.sqlite3
│  main.py
│  manage.py
│
└─VeryControl
        asgi.py
        settings.py
        urls.py
        wsgi.py
        __init__.py

我特意给它做了一个应用程序版的,内置 第 1.3.0.0 1.3.0.0 1.3.0.0 的服务器版本 它会自己更新,不用管它。

1. / m a i n . p y /main.py /main.py

这个程序的主要功能是:

  • 绘制 L O G O LOGO LOGO 。
  • 生成服务器,使得前端可以访问。
  • 检查是否有更新,如果没有直接运行服务器;如果有,就强制更新。


    第三条性质感觉有那么一种 W i n d o w s Windows Windows 的传奇色彩~ 
# Copyright 2022 by PanDaoxi. All rights reserved.
from socket import socket, AF_INET, SOCK_DGRAM
from os import system, name
from time import strftime, sleep
from colorama import init, Fore, Back
from requests import get

# 版本信息
version = "1.3.0.0 [2022-7-22 Update]"
# 更新文件的名称和网络地址
updateFiles = {
    "./manage.py": "https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/manage.py",
    __file__: "https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/main.py",
    "./VeryControl/asgi.py": "https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/VeryControl/asgi.py",
    "./VeryControl/settings.py": "https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/VeryControl/settings.py",
    "./VeryControl/urls.py": "https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/VeryControl/urls.py",
    "./VeryControl/wsgi.py": "https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/VeryControl/wsgi.py",
}
# 用户代理
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44",
}

# 获取IP地址
def getIP():
    try:
        sock = socket(AF_INET, SOCK_DGRAM)
        sock.connect(("8.8.8.8", 80))
        ip = sock.getsockname()[0]
    finally:
        sock.close()
    retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn ip

# 如果发现更新就一个一个地给文件更新为最新版本
def update():
    for i in updateFiles.keys():
        with open(i, "wb") as f:
            f.write(get(updateFiles[i], headers=headers).content)
        sleep(0.3)

if __name__ == "__main__" and name == "nt":
	# 获取最新版本号
    temp = get('https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/VeryControl/VERSION',headers=headers)
    temp.encoding = 'utf-8'
    latest = temp.text
    # 如果不一样就更新
    if latest != version:
        print('Please wait a moment, we are updating the software for you ...')
        update() # 你挡都挡不住!
    system('cls')
    # 画一只 楼狗(logo)
    print(
        """                                                                         _..._       .-'''-.                                    .-'''-.          
                                                                      .-'_..._''.   '   _                                     '   _      .---. 
 .----.     .----.   __.....__                                      .' .'      './   /` '.       _..._                     /   /` '.    |   | 
         /    /.-''         '.         .-.          .-           / .'          .   |       '  .'     '.                  .   |       ' |   | 
   '   '. /'   //     .-''"'-.  `. .-,.--.         / /          . '            |   '      |  '.   .-.   .     .|  .-,.--. |   '      |  '|   | 
   |    |'    //     /________   |  .-. |       / /           | |                     / / |  '   '  |   .' |_ |  .-. |         / / |   | 
   |    ||    ||                  || |  | |      / /            | |             `.   ` ..' /  |  |   |  | .'     || |  | | `.   ` ..' /  |   | 
   '.   `'   .'    .-------------'| |  | |     / /             . '                '-...-'`   |  |   |  |'--.  .-'| |  | |    '-...-'`   |   | 
            /      '-.____...---.| |  '-     `  /                '.          .              |  |   |  |   |  |  | |  '-                |   | 
           /    `.             .' | |           /                 '. `._____.-'/              |  |   |  |   |  |  | |                    |   | 
      '----'       `''-...... -'   | |         / /                    `-.______ /               |  |   |  |   |  '.'| |                    '---' 
                                   |_|     |`-' /                              `                |  |   |  |   |   / |_|                          
                                            '..'                                                '--'   '--'   `'-'                               nn"""
    )
	# 配置 colorama
    init(autoreset=True)
    # 欢迎信息及服务器地址(高亮标红)
    print(
        "Welcome to Very_Control (Version %s) !nControlled end:" % version,
        Fore.RED + "http://%s:%s/n" % (getIP(), strftime("%Y")),
    )
    # 运行服务器
    system("python manage.py runserver %s:%s" % (getIP(), strftime("%Y")))
    # 如果服务器运行期间出现BUG,这样就不会退出了。
    input()

2. / V e r y C o n t r o l / u r l s . p y /VeryControl/urls.py /VeryControl/urls.py

这是服务器的核心,我们靠它进行一系列的控制。

from django.urls import path as site
from django.shortcuts import HttpResponse
from os import system, remove, environ
from base64 import a85decode, b64encode
from sys import path
from requests import get
from pyautogui import screenshot
from tkinter import Tk
from time import strftime, sleep
from cv2 import VideoCapture, imwrite

def getVersion():
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44",
    }
    temp = get(
        "https://pandaoxi.coding.net/p/pandaoxi/d/Projects/git/raw/master/Very_Control/VeryControl/VERSION",
        headers=headers,
    )
    temp.encoding = "utf-8"
    retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn temp.text


# 求最大公因数
def gcd(a, b):
    if b == 0:
        retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn a
    else:
        retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn gcd(b, a % b)


# 适配图片比例
def change(a, b):
    x = gcd(a, b)
    a /= x
    b /= x
    while a < 500 or b < 500:
        a *= 2
        b *= 2
    retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn (a, b)


# 拍照
def get_photo():
    cap = VideoCapture(0)
    f, frame = cap.read()
    imwrite("./photo.png", frame)
    with open("./photo.png", "rb") as f:
        temp = b64encode(f.read()).decode()
    remove("./photo.png")
    cap.release()
    retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn "data:image/png;base64,%s" % temp


# 主页
def main(request):
    retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse(
        """Very Control


    
Very Control 多对一远程控制平台

输入命令:

带有回显的命令:

提交批处理文件的源代码:

或者使用应用程序提交工具



当前软件信息:

版本: %s

开发者:PanDaoxi

开源地址:点击这里去访问!

开发者邮箱(欢迎意见反馈和技术支持):


其他功能:截取屏幕tt查看被控制者信息tt捕获摄像头tt发送消息tt阅读官方通知

""" % getVersion() ) # 阅读通知 def readNotice(request): retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse( """阅读官方通知 官方通知

页面加载较慢是正常现象,请耐心等候。



回到主页
""" ) # 运行 def run(request): system("chcp 65001 >nul") text = request.POST.get("command") code = request.POST.get("code") runf = request.POST.get("runf") echo = request.POST.get("echo") if code: # 优先级最高的 执行批处理脚本 with open("temp.bat", "w", encoding="utf-8") as f: f.write(code + "nexit") system("start %s\temp.bat" % path[0]) if runf: # 次之的应用程序 with open("temp.exe", "wb") as f: f.write(a85decode(runf.encode())) system("start %s\temp.exe" % path[0]) if text: # 最后是直接执行命令 system(text) if echo: # 带回显的执行命令 try: remove("temp.txt") except: pahttps://blog.csdn.net/PanDaoxi2020/article/details/ss system("%s >> temp.txt" % echo) with open("temp.txt", "r", encoding="utf-8") as f: ret = f.read().splitlines() s = "" for i in ret: s += "

%s

n" % i retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse( """程序运行结果 %s


回到主页
""" % s ) retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse('') # 截图 def https://blog.csdn.net/PanDaoxi2020/article/details/ss(request): window = Tk() window.withdraw() width = window.whttps://blog.csdn.net/PanDaoxi2020/article/details/info_screenwidth() height = window.whttps://blog.csdn.net/PanDaoxi2020/article/details/info_screenheight() image = screenshot(region=(0, 0, width, height)) image.save("./screenshot.png") with open("./screenshot.png", "rb") as f: content = b64encode(f.read()).decode() remove("./screenshot.png") w, h = change(width, height) retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse( """Screen Shot



回到主页tt重新截图
""" % (content, h, w) ) window.mainloop() # 环境信息 def https://blog.csdn.net/PanDaoxi2020/article/details/inf(request): system("chcp 65001 >nul") s1 = "" for i in environ.keys(): s1 += "

%st%s

n" % (i, environ[i]) try: remove("temp.txt") except: pahttps://blog.csdn.net/PanDaoxi2020/article/details/ss system("tasklist>>temp.txt") with open("temp.txt", "r", encoding="utf-8") as f: s2 = f.read().splitlines() remove("temp.txt") s3 = "" for i in s2: s3 += "

%s

n" % i retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse( """Os_Environ 系统环境变量 %s


运行的进程(如需对齐可以看此网页的源代码) %s


返回主页
""" % (s1, s3) ) # 拍照 def https://blog.csdn.net/PanDaoxi2020/article/details/camera(request): retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse( """摄像头捕获


该功能可能会比较卡顿;如果不能正常显示出摄像头图像,可能是因为被控制设备的摄像头无法访问。



回到主页tt重新拍照
""" % get_photo() ) # 发送消息文本 def sendMehttps://blog.csdn.net/PanDaoxi2020/article/details/ssage(request): retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse( """发送消息文本
Very Control - 消息发送器

输入发送给被控制端的消息,消息将会以警示框的形式表现:




回到主页
""" ) # 显示信息 def showMehttps://blog.csdn.net/PanDaoxi2020/article/details/ssage(request): msg = request.POST.get("msg") with open("temp.py", "w+", encoding="utf-8") as f: f.write("from easygui import msgboxnmsgbox('''%s''',"Very Control")" % msg) system("start /min cmd /c temp.py") retuhttps://blog.csdn.net/PanDaoxi2020/article/details/rn HttpResponse("""""") urlpattehttps://blog.csdn.net/PanDaoxi2020/article/details/rns = [ site("", main), site("https://blog.csdn.net/PanDaoxi2020/article/details/jump", main), site("run", run), site("https://blog.csdn.net/PanDaoxi2020/article/details/ss", https://blog.csdn.net/PanDaoxi2020/article/details/ss), site("https://blog.csdn.net/PanDaoxi2020/article/details/inf", https://blog.csdn.net/PanDaoxi2020/article/details/inf), site("https://blog.csdn.net/PanDaoxi2020/article/details/cam", https://blog.csdn.net/PanDaoxi2020/article/details/camera), site("https://blog.csdn.net/PanDaoxi2020/article/details/sendm", sendMehttps://blog.csdn.net/PanDaoxi2020/article/details/ssage), site("showm", showMehttps://blog.csdn.net/PanDaoxi2020/article/details/ssage), site("https://blog.csdn.net/PanDaoxi2020/article/details/rn", readNotice), ]
最后

有些时候,有些BUG,总也改不掉。还是需要专业的力量的。

对此感谢博客园和菜鸟教程的帮助!

完美结束。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1029124.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号