Sha256: 198c3cf60103f92ed61d4893fdd7fe7b884c43cac3f695cffa5e6f62ccb32472

Contents?: true

Size: 679 Bytes

Versions: 4

Compression:

Stored size: 679 Bytes

Contents

require "packetgen"
require "oj"
require "pcap2json/version"
require "pcap2json/packetgen_extensions"

module Pcap2JSON
  def self.from_file(filename)
    PacketGen::PcapNG::File.new.read_packets(filename) do |packet|
      yield packet.to_json
    end
  rescue StandardError => e
    raise ArgumentError, e unless File.extname(filename.downcase) == '.pcap'
    PCAPRUB::Pcap.open_offline(filename).each_packet do |packet|
      next unless (packet = PacketGen.parse(packet.to_s))
      yield packet.to_json
    end
  end

  def self.from_interface(interface, **options)
    PacketGen.capture(iface: interface, **options) do |packet|
      yield packet.to_json
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pcap2json-1.0.2 lib/pcap2json.rb
pcap2json-1.0.1 lib/pcap2json.rb
pcap2json-1.0.0 lib/pcap2json.rb
pcap2json-0.1.0 lib/pcap2json.rb