-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLenovo.py
More file actions
95 lines (86 loc) · 1.97 KB
/
Lenovo.py
File metadata and controls
95 lines (86 loc) · 1.97 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from pickle_socket import PickleSocket
import sys
import rsa
from os import system as cmd
import os
import tree
import socket
from interactive import listen
def main():
global s
s=openPort()
print('Enter to accept...')
if listen() != b'\r':
s.close()
input('Aborted! Enter...')
sys.exit(1)
os.chdir('D:/')
op=s.recvObj()
while op != 'en':
print(op)
if op=='ls':
ls()
elif op=='cd':
cd()
elif op=='cf':
cf()
elif op=='tf':
tf()
elif op=='td':
td()
else:
s.close()
input('Error: Strange command! ')
op=s.recvObj()
s.close()
input('Session ends. Enter...')
def openPort():
print('Lenovo IP =',socket.gethostbyname(socket.gethostname()))
ss=PickleSocket()
ss.bind(('',2336))
ss.listen(1)
print('Listening...')
s,addr=ss.accept()
print('Connection from',addr)
return s
def ls():
global s
s.sendObj(os.listdir())
def cd():
global s
try:
os.chdir(s.recvObj())
s.sendObj(os.getcwd())
except Exception:
s.sendObj(b'error')
def cf():
global s
filename=s.recvObj()
if os.path.isfile(filename):
s.sendObj(True)
s.sendObj(os.path.getsize(filename))
else:
s.sendObj(False)
def tf():
global s
filename=s.recvObj()
s.sendObj(os.path.getsize(filename))
s.socket.sendfile(open(filename,'rb'))
def td():
global s
root=tree.mirror(os.getcwd())
s.sendObj(root)
if s.recvObj()=='y':
sendFullDir(s,root)
s.sendObj(b'ok')
def sendFullDir(pickleSocket,folder):
for i in folder.sub_file:
file_len=os.path.getsize(i.name)
pickleSocket.sendObj(file_len)
pickleSocket.socket.sendfile(open(i.name,'rb'))
for i in folder.sub_folder:
os.chdir(i.name)
sendFullDir(pickleSocket,i)
os.chdir('..')
main()
sys.exit(0)