forked from mariusv/Gray-Hacker-and-PenTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reading_socket.py
executable file
·63 lines (41 loc) · 936 Bytes
/
reading_socket.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
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
#!/usr/bin/env python
__author__ = "bt3"
import os
import socket
from subprocess import Popen, STDOUT, PIPE
# Defining constants
SHELL_COMMAND = "nc 54.209.5.48 12345"
def next_line(stdout):
# read inputs in lines
line = ""
while True:
r = stdout.read(1)
if r == '\n':
break
line += r
return line
def write(stdin,val):
# write outputs
stdin.write(val)
def nl():
# next line for iteration
return next_line(p.stdout)
def wr(val):
# write for iteration
write(p.stdin,val)
def ntext():
line = ""
while "psifer text:" not in line:
line = nl()
return line[len("psifer text:") + 1:]
def main():
p = Popen(SHELL_COMMAND, shell=True, cwd="./", stdin=PIPE,
stdout=PIPE, stderr=STDOUT,close_fds=True)
while True:
text = ntext()
text += " -> just an example"
wr(ans + '\n')
ret = p.wait()
print "Return code: %d" % ret
if __name__ == '__main__':
main()