(request, task_id, conntuple)
return HttpResponse(json.dumps(packets), content_type="application/json")
Get packets from the task PCAP related to a certain connection.
    This is possible because we sort the PCAP during processing and remember offsets for each stream.
Get packets from the task PCAP related to a certain connection.
    This is possible because we sort the PCAP during processing and remember offsets for each stream.
Get packets from the task PCAP related to a certain connection . This is possible because we sort the PCAP during processing and remember offsets for each stream .
def pcapstream(request, task_id, conntuple):
    """Get packets from the task PCAP related to a certain connection.
    This is possible because we sort the PCAP during processing and remember offsets for each stream.
    """
    src, sport, dst, dport, proto = conntuple.split(",")
    sport, dport = int(sport), int(dport)

    conndata = results_db.analysis.find_one(
        {
            "info.id": int(task_id),
        },
        {
            "network.tcp": 1,
            "network.udp": 1,
            "network.sorted_pcap_id": 1,
        },
        sort=[("_id", pymongo.DESCENDING)])

    if not conndata:
        return view_error(request, "The specified analysis does not exist")

    try:
        if proto == "udp":
            connlist = conndata["network"]["udp"]
        else:
            connlist = conndata["network"]["tcp"]

        conns = filter(lambda i: (i["sport"], i["dport"], i["src"], i["dst"]) == (sport, dport, src, dst), connlist)
        stream = conns[0]
        offset = stream["offset"]
    except:
        return view_error(request, "Could not find the requested stream")

    try:
        fobj = fs.get(conndata["network"]["sorted_pcap_id"])
        setattr(fobj, "fileno", lambda: -1)
    except:
        return view_error("The required sorted PCAP does not exist")

    packets = list(network.packets_for_stream(fobj, offset))
    # TODO: starting from django 1.7 we should use JsonResponse.
    return HttpResponse(json.dumps(packets), content_type="application/json")
def pcapstream ( request , task_id , conntuple ) : src , sport , dst , dport , proto = conntuple . split ( "," ) sport , dport = int ( sport ) , int ( dport ) conndata = results_db . analysis . find_one ( { "info.id" : int ( task_id ) , } , { "network.tcp" : 1 , "network.udp" : 1 , "network.sorted_pcap_id" : 1 , } , sort = [ ( "_id" , pymongo . DESCENDING ) ] ) if not conndata : return view_error ( request , "The specified analysis does not exist" ) try : if proto == "udp" : connlist = conndata [ "network" ] [ "udp" ] else : connlist = conndata [ "network" ] [ "tcp" ] conns = filter ( lambda i : ( i [ "sport" ] , i [ "dport" ] , i [ "src" ] , i [ "dst" ] ) == ( sport , dport , src , dst ) , connlist ) stream = conns [ 0 ] offset = stream [ "offset" ] except : return view_error ( request , "Could not find the requested stream" ) try : fobj = fs . get ( conndata [ "network" ] [ "sorted_pcap_id" ] ) setattr ( fobj , "fileno" , lambda : - 1 ) except : return view_error ( "The required sorted PCAP does not exist" ) packets = list ( network . packets_for_stream ( fobj , offset ) ) # TODO: starting from django 1.7 we should use JsonResponse. return HttpResponse ( json . dumps ( packets ) , content_type = "application/json" )