Created
May 27, 2024 13:53
-
-
Save shijiezhou1/c8ea70f2a2cc3b70ff30fc91048f4bf1 to your computer and use it in GitHub Desktop.
Client site command sender
This file contains 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