SoFunction
Updated on 2024-11-19

Local Area Network (LAN) control of computers with Python

The program is divided into two parts, one is the client side which is also the manipulated port and the other is the server side which is used to manipulate the manipulated port.

The program is very simple, is transformed through the LAN chat system, there is no advanced GUI framework, only simple DOS window, this is for learning purposes only, of course, you can also put the client in your second computer, and then use the server side of the command operation, is also very good.

The client will automatically get your IPv4 address and display it, you need to use the IP address given by the client to go to the server to connect. Execution of the instruction is also very simple, with the received data for () for execution. Ideas can also do a lot of mouse positioning data transfer, you can achieve the mouse to control the computer, the idea is great, the action is very difficult. This is a for learning

Client:

import socket
import os
import psutil
 
# Execute received commands
def send_data(data):
    (data)
    print('[-][+][~] Execute command: ['',data+']')
 
Database = (socket.AF_INET,socket.SOCK_STREAM)
 
# Obtain an IPv4 address
info = psutil.net_if_addrs()
wlan = info['WLAN']
def myaddr():
    for i in wlan:
        for myaddr in i:
            if '192.168' in str(myaddr):
                return myaddr
((myaddr(),8888))
(1)
def main():
    while True:   # Continuous cyclic execution
        try:      # Accepts data and commands and is considered disconnected if there is an error
            print(f'[#~]Current server IP address is [{myaddr()}]...')
            print('[#~]Waiting for connection...')
            sed,dree=()    # Waiting for server access
            print('[+] Connected to server...')
            while True:
                if (1024).decode('utf-8') == '':
                    break
                data = (1024).decode('utf-8')# Accepting data
                send_data(data)   # Send
        except:
            pass
        print('[-] Connection Disconnected ... \n')
 
if __name__ == "__main__":
    main()
 

The server needs the IP address output by the client to connect to, the output command try not to top off the DOS window of the client, such as cmd directly replaced, try to use start cmd that can be opened!

Server:

import socket
udp_socket = (socket.AF_INET,socket.SOCK_STREAM)
def main():
    while True:
        DATA = input('Please enter instructions:')
        if DATA == '':
            pass
        else:
            if len(DATA):
                udp_socket.send(('utf-8'))
                udp_socket.send(('utf-8'))
if __name__ == '__main__':
    myaddr = input('Enter the IP address of the server to which you want to connect:')
    udp_socket.connect((myaddr, 8888))  # Connecting to the server
    data_list = ''   # Testing
    udp_socket.send(data_list.encode('utf-8'))
    main()

We enter the IP address of the client, enter can see that there is no error that connects to the

This is the client side, you can see that the connection has been successful, we use the server-side operation of the command

On the server side, we start cmd and open cmd.

Client, you can see that the cmd window has been opened

To this article on the use of Python to achieve LAN control computer article is introduced to this, more related to Python domain control computer content please search my previous posts or continue to browse the following related articles I hope you will support me more in the future!