Esempio n. 1
0
def parse_packet(filename):
    with PcapReader(filename) as file_capture:
        global start_parse, end_parse, count, totaltime
        for packet in file_capture:
            try:
                if (
                        len(packet) > 400 and packet.dport == 1813
                ):  # We only need pcakets whose length is greater than 400 bytes
                    # Capturing the RAW data from packet (the index value for raw data is 3)
                    start_parse = time()
                    radius_packet = str(packet[Radius])
                    # Pyrad has a dictionary with the RADIUS attributes defined, It'll help in decoding the RAW Packet
                    pkt = Packet(packet=radius_packet,
                                 dict=Dictionary("dictionary"))
                    attr1 = pkt._DecodeKey(8)
                    value1 = pkt.__getitem__(attr1)
                    attr2 = pkt._DecodeKey(31)
                    value2 = pkt.__getitem__(attr2)
                    end_parse = time()
                    print("Time Taken to parse RADIUS packet: %s seconds" %
                          (end_parse - start_parse))
                    count += 1
                    totaltime += (end_parse - start_parse)
                    print("%d Private IP: %s and MSISDN: %s" %
                          (count, value1, value2))
            except AttributeError:
                print(
                    "Port attribute not available in the packet, skipping the parsing on the packet... "
                )
def parse_packet(packet):
    if (packet.haslayer(Radius)):
        radius_packet = str(packet[Radius])
        pkt = Packet(packet=radius_packet, dict=Dictionary("dictionary"))

        for key, value in pkt.iteritems():
            attr = pkt._DecodeKey(key)
            value = pkt.__getitem__(attr)
            #print attr, value
            fout.write("%s %s\n" % (attr, str(value)))
    else:
        #packet.show()
        pass