Пример #1
0
def main():
    if (len(sys.argv) > 1) and (sys.argv[1] != '-'):
        with open(sys.argv[1], 'rb') as fp:
            scanner = pcapng.FileScanner(fp)
            dump_information(scanner)
    else:
        scanner = pcapng.FileScanner(sys.stdin)
        dump_information(scanner)
Пример #2
0
    def __init__(self, fn, use_pcapng=None):
        self.fn = fn

        # Select library
        self.use_pcapng = use_pcapng
        if self.use_pcapng is None:
            # User higher performance library if available
            self.use_pcapng = False if pcap else True
        # self.pcapng = "pcapng" in argsj["parser"]
        if self.use_pcapng:
            assert pcapng, "pcapng library requested but no pcapng library"
        else:
            assert pcap, "pcap library requested but no pcap library"

        # Initialize library
        if self.use_pcapng:
            self.fp = open(fn, 'rb')
            self.scanner = pcapng.FileScanner(self.fp)
            self.scanner_iter = self.scanner.__iter__()
        else:
            self.pcap = pcap.pcapObject()
            self.pcap.open_offline(fn)
Пример #3
0
import sys

import pcapng
import scapy.layers.l2
import scapy.layers.inet

import flexlib

fn = 'FlexCapture.pcapng'
if len(sys.argv) > 2:
    fn = sys.argv[1]

dst_address = '10.0.1.44'

packets = []
with open(fn, 'r') as fp:
    scanner = pcapng.FileScanner(fp)
    for b in scanner:
        if isinstance(b, pcapng.blocks.EnhancedPacket):
            e = scapy.layers.l2.Ether(b.packet_data)
            p1 = e.payload
            if isinstance(p1, scapy.layers.inet.IP):
                p2 = p1.payload
                if isinstance(p2, scapy.layers.inet.TCP):
                    pass
                elif isinstance(p2, scapy.layers.inet.UDP):
                    if p1.dst == dst_address and p1.dport == 4991:
                        flp = flexlib.vita.protocol.parse_packet(
                            p2.payload.original)
                        packets.append(flp)
Пример #4
0
#!/usr/bin/env python

from __future__ import print_function

import sys

import pcapng


def dump_information(scanner):
    for block in scanner:
        print(block)


if __name__ == "__main__":
    if len(sys.argv) > 1:
        with open(sys.argv[1], "rb") as fp:
            scanner = pcapng.FileScanner(fp)
            dump_information(scanner)

    else:
        scanner = pcapng.FileScanner(sys.stdin)
        dump_information(scanner)