Python TCP raw socket not listening on lo (localhost/ 127.0.0.1)
<p>I created a simple packet sniffer using raw socket in Python.</p>

<pre><code>import socket

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)

while True:
    print s.recvfrom(1600)
</code></pre>

<p>The internet traffic it's showing. But when I turn the primary network interface down and send syn packets using scapy through the <code>lo</code> interface (source and destination 127.0.0.1), There's nothing printed.</p>

<p>Basically I create and send 10 syn packets using scapy whose source and destination is 127.0.0.1, which is visible in wireshark. But not in this sniffer. I thought there might be a problem of the length. So I set the buffer size to a syn packet's size i.e. 74 (<code>s.recvfrom(74)</code>), but still nothing. As soon as I turn the primary network interface up again, it shows all the TCP traffic.</p>

<p>I need to turn off the network interface so that I won't receive any other traffic other than my own created one.</p>

<p>Where I'm going wrong with this? </p>