Exemplo n.º 1
0
def save_pcap(interface, filename):
    """
        Capture network traffic and save it to disk
        
        @param interface: network interface, e.g. eth0
        @param filename: filename to store pcap in
    """
    pcap_out = multiprocessing.Queue()
    pcap_writer = PcapWriter(filename, pcap_out)
    pcap_writer.start()
    net_sensor = NetworkSensor(interface)

    while True:
        pkt = net_sensor.read()
        if pkt is None:
            break

        pcap_out.put((pkt[0], str(pkt[1])))

    pcap_out.close()
    pcap_writer.stop()
Exemplo n.º 2
0
def main(options):

    # Initialize our sensor
    net = NetworkSensor(options.interface)

    # Open a file to store our capture
    f = open("test.pcap", "a+")
    writer = dpkt.pcap.Writer(f)

    while True:
        (ts, packet) = net.read()

        # Start analyzing our packet
        eth_packet = dpkt.ethernet.Ethernet(packet)

        # Print packets to screen
        print repr(eth_packet)

        writer.writepkt(packet)

        f.flush()

    f.close()
Exemplo n.º 3
0
def main(options):

    # Initialize our sensor
    net = NetworkSensor(options.interface)

    # Open a file to store our capture
    f = open("test.pcap", "a+")
    writer = dpkt.pcap.Writer(f)

    while True:
        (ts,packet) = net.read()
        
        # Start analyzing our packet
        eth_packet = dpkt.ethernet.Ethernet(packet)

        # Print packets to screen
        print repr(eth_packet)
        
        writer.writepkt(packet)
        
        f.flush()
        
    f.close()