module Pcap2JSON

Constants

VERSION

Public Class Methods

from_file(filename) { |to_json| ... } click to toggle source
# File lib/pcap2json.rb, line 7
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
from_interface(interface, **options) { |to_json| ... } click to toggle source
# File lib/pcap2json.rb, line 19
def self.from_interface(interface, **options)
  PacketGen.capture(iface: interface, **options) do |packet|
    yield packet.to_json
  end
end