I'm writing an application proxy for generic use.
I want to use this as a transparent proxy, where my original plan is to use iptables with a REDIRECT rule forward all connections to my application proxy.
The problem here is of course, that my application proxy lose the information about the intended destination.
Is it possible to query iptables to retrieve the originally intended recipient? Any other possible solution to this problem is also appreciated!
Perhaps this is what you were looking for?
http://www.network-builders.com/iptables-redirect-original-destination-ip-t69515.html
Read the
SO_ORIGINAL_DST
option of the TCP socket.
Or look up the connection tracking table in /proc/net/ip_conntrack.
#include <linux/netfilter_ipv4.h>
struct sockaddr_in addr;
socklen_t addr_sz = sizeof(addr);
memset(&addr, 0, addr_sz);
addr.sin_family = AF_INET;
getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &addr, &addr_sz);
I think you should be able to convert that to something similar for python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With