Python Packet Sniffing / Packet Capture - pcapy does not capture packets

I have my wireless interface in monitoring mode, and I can successfully sniff network packets and analyze them using Wireshark. I tried to implement something similar with pcapyand impacket. It pcapydoesn't seem to capture the same packets as Wireshark. I am currently working on Mac OS X 10.9 since 2012 Macbook Pro, but noticed that this behavior on Ubuntu using the TL-WN722N TP-LINK usb wireless adapter.

Here is an example script that I wrote that is clearly not working. I do not collect requests with help pcapy, although I see them in Wireshark.

import pcapy
import impacket

DECODER = impacket.ImpactDecoder.RadioTapDecoder()


def packet_handler(header, data):
   radio_packet = DECODER.decode(data)
   dot11 = radio_packet.child()
   if dot11.get_subtype() == impacket.dot11.Dot11Types.DOT11_SUBTYPE_MANAGEMENT_PROBE_REQUEST:
       management_base = dot11.child()
       if management_base.__class__ == impacket.dot11.Dot11ManagementFrame:
           print management_base.get_source_address(), management_base.get_destination_address()


p = pcapy.open_live("your_interface_here", 2000, 0, 1000)
p.loop(-1, packet_handler)

en1 . pcap, Wireshark, open_live open_offline:

p = open_offline('path_to_file')

pcapy?

+4
1

, , Wireshark, promiscuous ( , ):

1) promiscuous pcapy

promiscuous = True
p = pcapy.open_live("your_interface_here", 2000, promiscuous, 1000)

2) promiscuous . , Mac, Linux :

os.system('sudo ifconfig eth0 promisc')

.

pcapy Ethernet. .

+1

Source: https://habr.com/ru/post/1534077/


All Articles