I have a linux machine with two ethernet ports, eth0
and eth1
. One port is connected to a network populated with hardware devices which can be controlled via ethernet. This is my "command network". The other port is connected to a network from which I send certain commands to the aforementioned devices, through a web-app on the linux machine's apache server. That network is the "control network."
What I would like to be able to do is allow for either network's IP address to be changed on command, regardless of which network is plugged into which port.
The idea is that the user would, in the web-app, enter the new IP address for either the command network or the control network and click submit, which would launch an AJAX request to the server. The server would then determine whether the request came from eth0
or eth1
, and then either change that port's IP address or the other port's IP address, depending on whether the command or control network was being changed.
Is there any way of determining which ethernet port the request came from in Python?
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 like127.0.0.1:8000
and the other interface to127.0.0.1:8001
.E.g.:
Then you could listen on both ports (
8000
and8001
) and tell them apart either by python instance (depending on your python web framework) or by destination port.