-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwoClient.py
More file actions
49 lines (40 loc) · 966 Bytes
/
Copy pathwoClient.py
File metadata and controls
49 lines (40 loc) · 966 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
37
38
39
40
41
42
43
44
45
46
47
48
49
import cmd
import socket
class woShell(cmd.Cmd):
"""Simple command processor."""
prompt = '> '
remote = True
ipPort = ()
def send(self, line):
"""send command """
if not self.remote:
print '> {}'.format(line)
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(self.ipPort)
try:
sock.sendall(line)
received = sock.recv(1024)
except Exception as msg:
print msg
else:
print(received)
finally:
sock.close()
def do_exit(self, line):
"""exit the shell, but leave the server running."""
return 1
do_q = do_exit
do_quit = do_exit
def do_help(self, arg):
self.default('?{}'.format(arg))
def default(self, line):
self.send(line)
def do_EOF(self, line):
"""^D um zu beenden"""
return True
if __name__ == "__main__":
sh = woShell()
#sh.remote = False
sh.ipPort = ( "localhost", 9999)
sh.cmdloop()