pythonsecuritynetwork-programmingwifilan

Why does my script stop execution after some time (pydivert)?


When I run this code, it works but then stops execution

import pydivert

with pydivert.WinDivert() as w:
    for pkt in w:
        pass

I was expecting it to run forever, dropping all the packets, but it stops working after some time.


Solution

  • Your code drops all of the packets and probably interferes with how windows functions. If you wish to do nothing with the packet you should send it on its way so that it arrives where it is expected, as follows:

    import pydivert
    
    with pydivert.WinDivert() as w:
        for pkt in w:
            w.send(pkt)
    

    I recommend being more selective about which packets you are dropping.