2017-03-03 4 views
1

PCAPLib独自のデータ構造を使わずにTCPパケットを個別に解析したいと考えています。そのため、私はTCPヘッダーのbytearrayを取得する必要があります。ByteArrayをpypcapfileのTCPヘッダーから取得する

from pcapfile import savefile 

capfile = open('delta_capture.pcap') 
sf = savefile.load_savefile(capfile) 

for packet in sf.packets: 
    print packet.timestamp 
    print packet.packet 
    print packet.header # Returns a library object, I need the bytearray instead, as I want to use my own data structure and parse. 

capfile.close() 

オブジェクト構造のデバッグと検査を試みましたが、TCPヘッダーに実際のバイトを格納するオブジェクトは見つかりませんでした。変数「パケット」のためのデバッガ結果について

スクリーンショット:

Screenshot for debugger result for the variable "packet"

は、このライブラリにそうすることも可能ですか?

答えて

0

ヘッダーのbytearrayには直接アクセスできません。ヘッダーのさまざまなフィールドが解析され、パケット全体が利用可能です。

for packet in sf.packets: 
    print(packet.timestamp) 
    print(packet.packet) 

    # show header fields 
    print(packet.header.contents.magic)   # file magic number 
    print(packet.header.contents.major)   # major version number 
    print(packet.header.contents.minor)   # minor version number 
    print(packet.header.contents.tz_off)   # timezone offset 
    print(packet.header.contents.ts_acc)   # timestamp accuracy 
    print(packet.header.contents.snaplen)  # snapshot length 
    print(packet.header.contents.ll_type)  # link layer header type 
    print(packet.header.contents.byteorder)  # byte order specifier 
    print(packet.header.contents.ns_resolution) # nanosecond resolution 

    # show entire packet 
    print(packet.raw()) 
関連する問題