Pyshark Экспорт данных в CSV - PullRequest
0 голосов
/ 22 мая 2018

Привет всем, я работаю с захватом данных и экспортом данных с помощью pyshark, поэтому у меня есть сетевой захват с именем "final_traces.pcap". Я могу проверить файл и даже распечатать данные из захватов с помощьюпомощь библиотеки под названием «PyShark», но я не могу экспортировать данные в формате csv.Я прилагаю фрагмент кода ниже.

>>> import pyshark
>>> cap = pyshark.FileCapture('./final_traces.pcap')
>>> print cap [0]
Packet (Length: 62)
Layer ETH:
    Destination: 00:0d:48:31:c4:fe
    .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
    Address: 00:0d:48:31:c4:fe
    .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
    Source: 40:8d:5c:f5:50:9f
    .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
    Address: 40:8d:5c:f5:50:9f
    .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
Layer IP:
    Source GeoIP: Unknown
    Destination GeoIP Longitude: 4.899500
    Destination GeoIP Latitude: 52.382401
    ..0. .... = More fragments: Not set
    Time to live: 128
    0100 .... = Version: 4
    .1.. .... = Don't fragment: Set
    Flags: 0x02 (Don't Fragment)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
    Identification: 0x7a48 (31304)
    Header checksum: 0xee23 [validation disabled]
    .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
    .... 0101 = Header Length: 20 bytes (5)
    Destination: 139.63.226.59
    Destination GeoIP Country: Netherlands
    0000 00.. = Differentiated Services Codepoint: Default (0)
    Fragment offset: 0
    0... .... = Reserved bit: Not set
    Total Length: 48
    Source: 192.168.100.56
    Header checksum status: Unverified
    Destination GeoIP AS Number: AS1103 SURFnet bv
    Protocol: TCP (6)
    Destination GeoIP: Netherlands, AS1103 SURFnet bv, Netherlands, AS1103 SURFnet bv, 52.382401, 4.899500
    Destination GeoIP Country: Netherlands
    Destination GeoIP AS Number: AS1103 SURFnet bv
Layer TCP:
    Calculated window size: 8192
    000. .... .... = Reserved: Not set
    .... ..0. .... = Urgent: Not set
    Acknowledgment number: 0
    TCP Option - No-Operation (NOP)
    Stream index: 0
    Checksum Status: Unverified
    Sequence number: 0    (relative sequence number)
    MSS Value: 1460
    TCP Segment Len: 0
    Connection establish request (SYN): server port 445
    Length: 4
    0111 .... = Header Length: 28 bytes (7)
    Destination Port: 445
    .... .... 0... = Push: Not set
    ...0 .... .... = Nonce: Not set
    .... ...0 .... = Acknowledgment: Not set
    TCP Option - Maximum segment size: 1460 bytes
    Expert Info (Chat/Sequence): Connection establish request (SYN): server port 445
    TCP Flags: \xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7S\xc2\xb7
    .... .... ...0 = Fin: Not set
    Kind: Maximum Segment Size (2)
    TCP Option - SACK permitted
    Window size value: 8192
    Group: Sequence
    Severity level: Chat
    Options: (8 bytes), Maximum segment size, No-Operation (NOP), No-Operation (NOP), SACK permitted
    Flags: 0x002 (SYN)
    .... .0.. .... = ECN-Echo: Not set
    Source Port: 38770
    Checksum: 0x4aaa [unverified]
    Urgent pointer: 0
    .... .... ..1. = Syn: Set
    .... 0... .... = Congestion Window Reduced (CWR): Not set
    .... .... .0.. = Reset: Not set
    TCP Option - No-Operation (NOP)
    Length: 2
    Kind: No-Operation (1)
    Kind: No-Operation (1)
    Kind: SACK Permitted (4)

Мне нужна помощь с тем, как я могу разместить определенные данные в формате CSV. Скажем, я хочу поместить Lat и Long в CSV.

1 Ответ

0 голосов
/ 25 мая 2018

Я не уверен, что бы вы сделали с python, но вы можете использовать cat foo.txt | grep -i "lat" | paste -d " " >> xyz.log для bash.

...