Tcpdump : Unable to capture packets from Python script
<p>I'm trying to open Tcpdump to capture UDP packets from a Python script. Here is my code:</p>

<pre><code>os.system("tcpdump -i wlp2s0 -n dst 8.8.8.8 -w decryptedpackets.pcap &amp;")
testfile = urllib.URLopener()
s = socket(AF_INET, SOCK_DGRAM)
host = "8.8.8.8"
port = 5000
buf = 1024
addr = (host, port)
s.connect((host, port))
f = open("file.txt", "rb")
data = f.read(buf)

while (data):
    if (s.sendto(data, addr)):
        print "sending ..."
        data = f.read(buf)
</code></pre>

<p>I am able to capture the packets (pcap file has content) if I manually execute this command in shell:</p>

<pre><code>tcpdump -i wlp2s0 -n dst 8.8.8.8 -w decryptedpackets.pcap &amp;
</code></pre>

<p>However, If I use os.system() I can't capture the packets. ( When I open the pcap file, I find it empty)</p>

<p>I have verified and found that there is a process that gets created when the Python script is executed:</p>

<blockquote>
  <p>root     10092  0.0  0.0  17856  1772 pts/19   S    10:25   0:00
  tcpdump -i wlp2s0 -n dst 8.8.8.8 -w decryptedpackets.pcap</p>
</blockquote>

<p>Also, I'm running this as a sudo user to avoid any permission problems.</p>

<p>Any suggestions what could be causing this problem ?</p>