pythonlinuxsocketsvirtualboxsniffer

Python Socket - Sniffer does not intercept all packets


My sniffer is running on linux via virtualbox. A network bridge with promiscuous mode between linux and windows. I want to intercept windows packets while on linux. But my program does not intercept these packets. However, it can do this if I run tcpdump and the program itself at the same time.

I created the socket as follows:

conn = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))

Solution

  • Add these lines to the code:

    import os
    os.system("ip link set {} promisc on".format(interface))
    

    It is necessary to enable promisc mode for the network interface.