Capturing packets with pcapy

We can use the open_live method in the pcapy interface to capture packets in a specific device and we can specify the number of bytes per capture and other parameters such as promiscuous mode and timeout.

In the following example, we'll count the packets that are capturing the eht0 interface.

You can find the following code in the capturing_packets.py file:

#!/usr/bin/python
import pcapy
devs = pcapy.findalldevs()
print(devs)
# device, bytes to capture per packet, promiscuous mode, timeout (ms)
cap = pcapy.open_live("eth0", 65536 , 1 , 0)
count = 1
while count:
(header, payload) = cap.next()
print(count)
count = count + 1
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.178