Created
May 27, 2024 13:53
Client site command sender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
HOST = '127.0.0.1' | |
PORT = 65432 | |
def send_command(conn, command): | |
conn.sendall(command.encode()) | |
while True: | |
data = conn.recv(1024) | |
if not data: | |
break | |
print(data.decode(), end="") | |
break | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.connect((HOST, PORT)) | |
print(f"已连接到{HOST}:{PORT}") | |
while True: | |
command = input("请输入命令(输入'exit'退出):") | |
if command.lower() == 'exit': | |
break | |
send_command(s, command + '\n') | |
print("命令执行完毕,请输入下一个命令。") | |
print("连接已关闭") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment