sshmitm.plugins.session.tcpserver module
A Python module for a TCP server that runs as a thread and accepts incoming connections.
This module contains the TCPServerThread class, which implements a basic TCP server that listens for incoming connections and launches a new thread for each connection request.
Example usage:
from sshmitm.plugins.session.tcpserver import TCPServerThread
def handle_request(server_address, client_socket, client_address):
print("Received connection from", client_address)
client_socket.sendall(b"Hello, client!")
client_socket.close()
server = TCPServerThread(request_handler=handle_request, port=1234)
server.start()
- class sshmitm.plugins.session.tcpserver.TCPServerThread(request_handler=None, network='127.0.0.1', port=0, run_status=True, daemon=False)
Bases:
ThreadA TCP server thread that accepts incoming connections and launches a new thread for each connection.
- Parameters:
request_handler (
Callable[[tuple[str,int],socket|Channel,tuple[str,int]],None] |None, default:None) – a function to be called for each connection requestnetwork (
str, default:'127.0.0.1') – network address for the server to bind toport (
int, default:0) – port number for the server to listen onrun_status (
bool, default:True) – whether the server should run or notdaemon (
bool, default:False) – whether the server should run as a daemon
- close()
Join all the active threads and close the server socket.
- Return type:
None
- handle_request(client, addr)
Call the handle request callback for a new connection.
- Parameters:
client (
socket|Channel) – The client’s socket or paramiko channel.addr (
tuple[str,int]) – Tuple containing the address information of the client.
- Return type:
None
- run()
Start the server thread and continuously check for incoming connections.
- Return type:
None