How to see every packet that comes to our computer?
<p>i wrote a very very easy script that monitors the Downloads folder for .part files, if there isn't any then it shuts down the computer and sends an email or text message. But i want to develop it by analyzing the packets to do that i need every packet that comes to our computer. How can i do that? or is there an easier way?</p>

<p>(If you download a file with Firefox or Chrome you will have a .part file which disappears when the download is finished.)
(www.github.com/berkQ/bdown/ for script.)</p>

<p>There actually is an easier way.</p>

<p>The cleanest I can think off would be monitoring the file system.</p>

<p>On linux you could use <code>pyinotify</code> : <a href="https://pypi.python.org/pypi/pyinotify/" rel="nofollow">https://pypi.python.org/pypi/pyinotify/</a>
<a href="https://github.com/seb-m/pyinotify/blob/master/python2/examples/loop.py" rel="nofollow">https://github.com/seb-m/pyinotify/blob/master/python2/examples/loop.py</a></p>

<p>On windows there are alternatives : <a href="http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html" rel="nofollow">http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html</a></p>

<p>You could as well write your own file watcher.</p>

<p>Every n seconds and For every file in downloads, get it's size. See if it has changed since last loop, if yes, assume there still are downloads.
If nothing changed during n loops, assume downloads are over.</p>

python network-programming