python-You can control the computer by sending commands through your mobile phone, let's find out!

"The  phone sends a command to completely control the computer "

Send commands through your mobile phone to control your computer. Doesn’t it sound cool? Want to know how to do it?

I won't tell you, I will never tell you that it is implemented in python!

01—Computer commands

To control the computer, we need to know what are the commonly used commands of the computer, so that we can operate it. Here, I will give a few small examples. If you want to know more, you can go to Baidu to search!

Commonly used commands:

dir displays the directory under the current path

cd into a directory

shutdown -r Shut down and restart.

calc-----------Start the calculator

dvdplay--------DVD player

explorer-------Open Explorer

regedit.exe-registry

ipconfig------- View host IP

control ------- open the control panel

To see more, here I will give you a website:

https://baike.baidu.com/item/%E7%94%B5%E8%84%91%E5%B8%B8%E8%A7%81%E5%91%BD%E4%BB%A4/492186

We know the order, so how do we use it?

02—Command control computer

Here we need to use a module we introduced last time, please see:

Semi-automated chatbot

The itchat, os module used here

Idea: The design idea here,

Send command-keyword recognition-call os module-run console command.

Let's look at the complete code:

import itchat
import os

@itchat.msg_register('Text') #注册文本消息
def text(msg):
    message =  msg['Text'] #接收文本消息
    toName = msg['ToUserName'] #接收方
    if toName == "filehelper":
        if "cmd" in message:
            m=str(message).split(" ")[1]#获得系统命令
            os.system(m)#执行命令
if __name__=="__main__":
    itchat.auto_login()
    itchat.send("登录成功!开始发消息吧!格式:cmd 命令 ","filehelper")
    #这里需要进入到文件传输助手中查看
    itchat.run()

 

Okay, here we have initially realized the control of the computer, then we will add another function on this basis;

I now want to send it a piece of code to execute:

Look at the simple implementation:

Store the sent code, and then call this module.

if "import" in message:
 #通过编写代码发送到电脑,电脑储存,然后执行代码。
   with open("command.py","w",encoding="utf-8") as f:
        f.write(message)
   import command

 

Then combine them:

import itchat
import os

@itchat.msg_register('Text') #注册文本消息
def text(msg):
    message =  msg['Text'] #接收文本消息
    toName = msg['ToUserName'] #接收方
    if toName == "filehelper":
        if "cmd" in message:
            m=str(message).split(" ")[1]#获得系统命令
            os.system(m)#执行命令
        if "import" in message:
            #通过编写代码发送到电脑,电脑储存,然后执行代码。
            with open("command.py","w",encoding="utf-8") as f:
                f.write(message)
                import command
                #调用我们写入数据的模块
if __name__=="__main__":
    itchat.auto_login()
    itchat.send("登录成功!开始发消息吧!","filehelper")
    #这里需要进入到文件传输助手中查看
    itchat.run()

Well, that's the end, and so on, you can add some other special commands, such as: turn on music, play movies, automatically turn off the power, and turn on the camera.

Like to remember to follow us!

Past review:

 How to make a girlfriend smile---accompany the confession robot

Automatic operation of the browser-no interface selenium crawler

Build your own voice chat robot

WeChat add friends automatically

Guess you like

Origin blog.csdn.net/qq_39046854/article/details/84351359