コード例 #1
0
def EasyParsePcap(filename=None, reader=None, from_side=None):
    '''
    Like ParsePcap, but makes and returns a PacketDispatcher for you.
    '''
    dispatcher = PacketDispatcher()
    ParsePcap(dispatcher, filename=filename, reader=reader, from_side=from_side)
    dispatcher.finish()
    return dispatcher
コード例 #2
0
ファイル: pcap.py プロジェクト: Angelcold/pcap2har
def EasyParsePcap(filename=None, reader=None):
    '''
    Like ParsePcap, but makes and returns a PacketDispatcher for you.
    '''
    dispatcher = PacketDispatcher()
    ParsePcap(dispatcher, filename=filename, reader=reader)
    dispatcher.finish()
    return dispatcher
コード例 #3
0
ファイル: pcapharconverter.py プロジェクト: linka/pcap2har
    def __init__(self, fileobj, drop_response_bodies=False):
        """
        Converts PCAP file to HAR format and keeps intermediate HttpSession object.

        Args:
            fileobj: file-like object, containing PCAP stream;
            drop_response_bodies: drop bodies in the HTTP response objects.
        """
        # PCAP 1Mb ~ 0.7s
        self.errors = []

        # parse pcap file
        dispatcher = PacketDispatcher()
        freader = ModifiedReader(fileobj)
        pcap_parser= PcapParser()
        pcap_parser.parse(dispatcher, reader=freader)
        self.errors.extend(pcap_parser.errors)
        dispatcher.finish()
         
        # arrange packets into http session
        self.session = HttpSession(dispatcher, drop_response_bodies)
        self.errors.extend(self.session.errors)
コード例 #4
0
ファイル: main.py プロジェクト: sajal/pcap2har
parser = optparse.OptionParser(
    usage='usage: %prog inputfile outputfile'
)
options, args = parser.parse_args()

# setup logs
logging.basicConfig(filename='pcap2har.log', level=logging.INFO)

# get filenames, or bail out with usage error
if len(args) == 2:
    inputfile, outputfile = args[0:2]
else:
    parser.print_help()
    sys.exit()

logging.info("Processing %s", inputfile)

# parse pcap file
dispatcher = PacketDispatcher()
pcap.ParsePcap(dispatcher, filename=inputfile)
dispatcher.finish()

# parse HAR stuff
session = httpsession.HttpSession(dispatcher)

logging.info("Flows=%d. HTTP pairs=%d" % (len(session.flows),len(session.entries)))

#write the HAR file
with open(outputfile, 'w') as f:
    json.dump(session, f, cls=har.JsonReprEncoder, indent=2, encoding='utf8')
コード例 #5
0
settings.process_pages = options.pages

# setup logs
logging.basicConfig(filename='pcap2har.log', level=logging.INFO)

# get filenames, or bail out with usage error
if len(args) == 2:
    inputfile, outputfile = args[0:2]
else:
    parser.print_help()
    sys.exit()

logging.info("Processing %s", inputfile)

# parse pcap file
dispatcher = PacketDispatcher()
pcap.ParsePcap(dispatcher, filename=inputfile)
dispatcher.finish()

# parse HAR stuff
session = httpsession.HttpSession(dispatcher)

logging.info("Flows=%d. HTTP pairs=%d" %
             (len(session.flows), len(session.entries)))

#write the HAR file
with open(outputfile, 'w') as f:
    json.dump(session,
              f,
              cls=har.JsonReprEncoder,
              indent=2,