-
Notifications
You must be signed in to change notification settings - Fork 0
/
netcat_STREAM-listener.py
44 lines (38 loc) · 1.08 KB
/
netcat_STREAM-listener.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
#!/usr/bin/env python3
#author: forestwhite/_kingfisher - https://github.com/forestwhite
'''
A spam listener: listens for spam strings sent via STREAM socket on
localhost:42424
'''
import socket
def handle(passedconn):
data = b""
newdata = passedconn.recv(size)
while newdata:
data += newdata
newdata = passedconn.recv(size)
if data:
datastring = data.decode("utf-8")
print(handlestring(datastring, len("spam "), "\n"))
passedconn.close()
def handlestring(datastring, length, delimiter):
stringlist = datastring.split(sep=delimiter)
filteredlist = []
for string in stringlist:
filteredlist.append(string[length:])
filteredstring = delimiter.join(filteredlist)
return filteredstring
def main():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
for i in [1,2,3]:
conn, clientaddress = s.accept()
handle(conn)
s.close()
host = "localhost"
port = 42424
backlog = 5
size = 1024
if __name__ == "__main__":
main()