模拟端口转发
()
| 358 | pass |
| 359 | |
| 360 | def proxy_handler(): |
| 361 | """模拟端口转发""" |
| 362 | try: |
| 363 | client, addr = proxy_server.accept() |
| 364 | data = client.recv(4096) |
| 365 | |
| 366 | # 转发到"容器内部" |
| 367 | upstream = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 368 | upstream.connect(("127.0.0.1", internal_port)) |
| 369 | upstream.sendall(data) # 转发请求 |
| 370 | response = upstream.recv(4096) # 收响应 |
| 371 | upstream.close() |
| 372 | |
| 373 | client.sendall(response) # 回传给客户端 |
| 374 | client.close() |
| 375 | except (socket.timeout, ConnectionRefusedError): |
| 376 | pass |
| 377 | |
| 378 | t1 = threading.Thread(target=internal_handler) |
| 379 | t2 = threading.Thread(target=proxy_handler) |
nothing calls this directly
no outgoing calls
no test coverage detected