-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.py
More file actions
45 lines (35 loc) · 1.16 KB
/
node.py
File metadata and controls
45 lines (35 loc) · 1.16 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
#!/usr/bin/env python
import socket
import select
import sys
import subprocess
import time
IP_address = socket.gethostname()
Port = 2004
acc = ['firefox', 'shutdown', 'gedit']
while True:
try:
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((IP_address, Port))
while True:
sockets_list = [sys.stdin, conn]
read_sockets, write_socket, error_socket = select.select(sockets_list, [], [])
for socks in read_sockets:
if socks == conn:
command = socks.recv(2048)
if not command:
raise Exception()
else:
for x in acc:
if x in command:
CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,stdin=subprocess.PIPE)
conn.send(CMD.stdout.read())
conn.send(CMD.stderr.read())
else:
continue
else:
continue
except:
time.sleep(10)
continue
server.close()