title: Intercept UDP packets passing through Linux Bridge with Python/iptables
body: <p>I am trying to use <code>iptables</code> on a layer 2 bridge running linux to get udp packets that are coming in from an ethernet port and going out on the wlan0 interface, and redirect them to a port on localhost (say, 10000).</p>
  
  <p>For example, if device1 (10.0.0.2) was sending udp packets via ethernet through the bridge (10.0.0.1) which was then passing that packet through to device2 (10.0.0.3) via the wireless interface, how would you redirect those packets to localhost (the bridge) so that a python script running on the bridge can process them?</p>
  
  <p>I've tried <code>iptables -t nat -A PREROUTING -d 10.0.0.3 -p udp --dport 10000 -j REDIRECT --to-ports 10000</code>, but it doesn't seem to work. The packets never get redirected.</p>
  
  <p>I've also tried <code>iptables -t nat -A PREROUTING -d 10.0.0.3 -p udp --dport 10000 -j DNAT --to-destination 127.0.0.1:10000</code> but no luck there either.</p>
  
  <p>Is there a way to do this with <code>iptables</code>, or with anything else? Otherwise, is there another way of intercepting the packets using Python alone? It's currently simply listening for UDP packets with:</p>
  
  <pre><code>socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  socket.bind(('', 10000))
  </code></pre>
  
  <p>Thank you.</p>