Is there any way of determining which ethernet port the request came from in Python?
Not readily.
However, what you could do is set up some iptables
rules to NAT port 80 on one interface to something like 127.0.0.1:8000
and the other interface to 127.0.0.1:8001
.
E.g.:
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8000
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8001
Then you could listen on both ports (8000
and 8001
) and tell them apart either by python instance (depending on your python web framework) or by destination port.