Skip to content

Commit d5067b1

Browse files
author
Artiom N.
committed
Transparent proxy example add
1 parent 39113cf commit d5067b1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)