I'm trying to do some sort of Session Initiation Protocol sniffer. I'm using the pyshark
module for python that offers me some functions to sniff packets from an interface. The thing is that there is a function called sniff()
that when I give a parameter packet_count=0
it checks for packets indefinitely until I stop the whole program.
What I want to know if there is a way to stop the cap.sniff()
function and retrieve the cap._packets
(which is a list) and then let the rest of the program run.
Here is the code that I made:
def sniffsip():
cap = pyshark.LiveCapture(interface='Ethernet')
cap.sniff(packet_count=0)#This is function sniff() that checks for packets
udp_packets = []
for i in cap._packets:
j = cap._packets.index(i)
if cap._packets[j].transport_layer == 'UDP' and cap._packets[j].highest_layer == 'SIP':
udp_packets.append(cap._packets[j])
return udp_packets