| 27 | ) |
| 28 | |
| 29 | def client_connected(self, client): |
| 30 | parts = client.peername[0].rsplit("%", 1) |
| 31 | address = ipaddress.ip_address(parts[0]) |
| 32 | if isinstance(address, ipaddress.IPv6Address): |
| 33 | address = address.ipv4_mapped or address |
| 34 | |
| 35 | if address.is_loopback or isinstance(client.proxy_mode, mode_specs.LocalMode): |
| 36 | return |
| 37 | |
| 38 | if ctx.options.block_private and address.is_private: |
| 39 | logging.warning( |
| 40 | f"Client connection from {client.peername[0]} killed by block_private option." |
| 41 | ) |
| 42 | client.error = "Connection killed by block_private." |
| 43 | |
| 44 | if ctx.options.block_global and address.is_global: |
| 45 | logging.warning( |
| 46 | f"Client connection from {client.peername[0]} killed by block_global option." |
| 47 | ) |
| 48 | client.error = "Connection killed by block_global." |