Posted By

scyclops on 08/27/07


Tagged

networking pcap


Versions (?)



Who likes this?

3 people have marked this snippet as a favorite

gedittest
yarvin
fukami


Live Packet Capture in Python with pcapy


Published in: Python 






URL: http://andrewtrusty.com/

Tried using pypcap but it didn't seem to do anything and I am too lazy to compile python-libpcap.

Requires: - pcapy python module (http://oss.coresecurity.com/projects/pcapy.html) - impacket python module (http://oss.coresecurity.com/projects/impacket.html) - pcap library, for Windows use WinPCap (http://www.winpcap.org/)

Sources: - http://oss.coresecurity.com/pcapy/doc/pt01.html - http://www.thescripts.com/forum/post2740081-5.html

Expand | Embed | Plain Text
  1. import pcapy
  2. from impacket.ImpactDecoder import *
  3.  
  4. # list all the network devices
  5. pcapy.findalldevs()
  6.  
  7. max_bytes = 1024
  8. promiscuous = False
  9. read_timeout = 100 # in milliseconds
  10. pc = pcapy.open_live("name of network device to capture from", max_bytes, promiscuous, read_timeout)
  11.  
  12. pc.setfilter('tcp')
  13.  
  14. # callback for received packets
  15. def recv_pkts(hdr, data):
  16. packet = EthDecoder().decode(data)
  17. print packet
  18.  
  19. packet_limit = -1 # infinite
  20. pc.loop(packet_limit, recv_pkts) # capture packets

Report this snippet 

You need to login to post a comment.