INNER CODE UNIT · Python

_peer_ip

cipi-sh/cipi · lib/cipi-crowdsec-rescue.py:56

def _peer_ip(handler: BaseHTTPRequestHandler) -> str:
    # Socket peer only. Headers that claim a client IP are ignored on purpose.
    host = handler.client_address[0]
    if host.startswith("::ffff:"):
        host = host[7:]
    return host


def _rate_ok(ip: str) -> bool:
    now = time.monotonic()
    with _fails_lock:
        q = _fails[ip]
        while q and now - q[0] > WINDOW:
            q.popleft()
        return len(q) < MAX_FAILS


def _rate_hit(ip: str) -> None:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…