We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f0ca994 commit f6df785Copy full SHA for f6df785
简单的SSH工具/ssh_client.py
@@ -0,0 +1,25 @@
1
+import socket
2
+
3
+cilent = socket.socket() #声明socket类型,同时生成socket对象
4
5
+cilent.connect(('localhost',6969))
6
7
+while True:
8
+ cmd = input(">>:").strip()
9
+ if len(cmd) == 0:
10
+ continue
11
+ cilent.send(cmd.encode("utf-8"))
12
+ cmd_res_size = cilent.recv(1024)#接收命令长度
13
+ print("命令结果大小:",cmd_res_size)
14
+ received_size = 0
15
+ received_data = b''
16
+ while received_size < int(cmd_res_size.decode()):
17
+ data = cilent.recv(1024)
18
+ received_size += len(data) #每次收到的实际长度
19
+ received_data += data
20
+ else:
21
+ print("cmd res receive done...",received_size)
22
+ print(received_data.decode())
23
24
+cilent.close()
25
0 commit comments