-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
channel_server.py
52 lines (46 loc) · 1.39 KB
/
channel_server.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
import socket
import json
import time
from threading import Thread, Lock
from lib import CSNSocket
from lib import p8, p16, p32, p64
from server_packets import *
class Channel_Server(Thread):
def __init__(self, lock, tcp_port=7011):
"""
Create a new tcp server
"""
Thread.__init__(self)
self.lock = lock
self.tcp_port = int(tcp_port)
self.is_listening = True
self.msg = '{"success": "%(success)s", "message":"%(message)s"}'
def run(self):
"""
Start tcp server
"""
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.bind(("0.0.0.0", self.tcp_port))
self.sock.setblocking(0)
self.sock.settimeout(1)
time_reference = time.time()
self.sock.listen(1)
while self.is_listening:
try:
conn, addr = self.sock.accept()
except socket.timeout:
continue
csnsocket = CSNSocket()
time_reference = time.time()
print(f"Channel server {time_reference}: {addr} connected.")
payload = opcode_01()
# print(conn.recv(1024))
conn.sendall(csnsocket.build(payload))
conn.close()
print("[-] Channel server Closed")
self.stop()
def stop(self):
"""
Stop tcp data
"""
self.sock.close()