guard_shells

Guard shells for connection limiting and robot detection.

When running a telnet server on a public IPv4 address, or even on large private networks, various network scanners, scrapers, worms, bots, and other automatons will connect.

The robot_check function detects whether the remote end is a real terminal emulator by requesting a cursor position report (CPR) after writing a single space character. Real terminals respond to CPR, while bots typically timeout.

These shells are used when normal shell access is denied due to connection limits or failed robot checks.

async robot_check(reader, writer, timeout=5.0)[source]

Check if client responds to cursor position report.

Return type:

bool

Returns:

True if client passes (responds to CPR with expected width).

async robot_shell(reader, writer)[source]

Shell for failed robot checks.

Asks philosophical questions, logs responses, and disconnects.

Return type:

None

async busy_shell(reader, writer)[source]

Shell for when connection limit is reached.

Displays busy message, logs any input, and disconnects.

Return type:

None

class ConnectionCounter(limit)[source]

Simple shared counter for limiting concurrent connections.

Initialize connection counter.

Parameters:

limit (int) – Maximum number of concurrent connections.

try_acquire()[source]

Try to acquire a connection slot.

Returns True if successful.

Return type:

bool

release()[source]

Release a connection slot.

Return type:

None

property count: int

Current connection count.