2011-02-09 17 views
23

Python için bir pcap kütüphanesinin önerisini almak istiyorum. .pcap dosyası ayrıştırma üzerinde proje yapıyorum. Google'da arama yaptım ve pylibpcap'ı buldum. Dışarıda başka bir şey var mı? Hangi kütüphaneyi tercih edersiniz ve neden?pcap python kitaplığı?

Teşekkürler. Bunu denedim ve pcapy denedim.

+0

Merhaba PSS, projenizi nasıl tamamladınız? hangi yaklaşıyor takip etti? –

cevap

16

scapy deneyin. Paket incelemesi, manipülasyonu ve oluşturulması için çok güçlü bir programdır.

build your own tools için kullanabilirsiniz.

+0

http://github.com/phaethon/scapy adresindeki yeni scapy sürümünü görün. Python3 ile uyumludur ve yeni işlevsellik içerir. –

+4

Python kitaplıkları için sıradışı bir şekilde scapy'ın GPLv2 olduğunu unutmayın - kütüphane muafiyetlerini dikkate almayın, bu nedenle içe aktarma scapy'ı yazmak kodunuzu GPLv2'ye zorlar - Bununla sorun yoksa, bunun için gidin. – Hal

14

Ben pcapy'yi seçtim çünkü kullanımım googling'i bulduğum bir örneğe benziyordu.

http://snipplr.com/view/3579/live-packet-capture-in-python-with-pcapy/

(ya da aşağıda kopyalanan aynı kodu görmek)

import pcapy 
from impacket.ImpactDecoder import * 

# list all the network devices 
pcapy.findalldevs() 

max_bytes = 1024 
promiscuous = False 
read_timeout = 100 # in milliseconds 
pc = pcapy.open_live("name of network device to capture from", max_bytes, 
    promiscuous, read_timeout) 

pc.setfilter('tcp') 

# callback for received packets 
def recv_pkts(hdr, data): 
    packet = EthDecoder().decode(data) 
    print packet 

packet_limit = -1 # infinite 
pc.loop(packet_limit, recv_pkts) # capture packets 
5

Pyshark'ı kullanmanızı tavsiye ederim. Bu tshark için sarıcı. Ayrıca tüm tshark filtresini, decoder lib'i destekliyor ... ve kullanımı kolay!

import pyshark 
cap = pyshark.FileCapture('/root/log.cap') 
cap 
>>> <FileCapture /root/log.cap> 
print cap[0] 
Packet (Length: 698) 
Layer ETH: 
     Destination: BLANKED 
     Source: BLANKED 
     Type: IP (0x0800) 
Layer IP: 
     Version: 4 
     Header Length: 20 bytes 
     Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport)) 
     Total Length: 684s 
     Identification: 0x254f (9551) 
     Flags: 0x00 
     Fragment offset: 0 
     Time to live: 1 
     Protocol: UDP (17) 
     Header checksum: 0xe148 [correct] 
     Source: BLANKED 
     Destination: BLANKED 
    ... 
dir(cap[0]) 
['__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__getitem__', '__getstate__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_packet_string', 'bssgp', 'captured_length', 'eth', 'frame_info', 'gprs-ns', 'highest_layer', 'interface_captured', 'ip', 'layers', 'length', 'number', 'pretty_print', 'sniff_time', 'sniff_timestamp', 'transport_layer', 'udp'] 
cap[0].layers 
[<ETH Layer>, <IP Layer>, <UDP Layer>, <GPRS-NS Layer>, <BSSGP Layer>] 
.... 
İlgili konular