예제 #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()
예제 #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()
예제 #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()