We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 39113cf commit d5067b1Copy full SHA for d5067b1
src/book01/ch21/python/transparent-proxy.py
@@ -0,0 +1,21 @@
1
+#!/usr/bin/env python3
2
+
3
+import socket
4
5
6
+IP_TRANSPARENT = 0x13
7
8
9
+with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
10
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
11
+ sock.setsockopt(socket.IPPROTO_IP, IP_TRANSPARENT, 1)
12
13
+ sock.bind(('8.8.8.8', 1234))
14
+ sock.listen()
15
16
+ print(f'Listening on {sock.getsockname()}')
17
+ while True:
18
+ cln_sock, (remote_ip, remote_port) = sock.accept()
19
+ local_ip, local_port = cln_sock.getsockname()
20
+ print(f'Connection from {remote_ip}:{remote_port} to {local_ip}:{local_port}')
21
+ cln_sock.close()
0 commit comments