Module: Pcap2JSON

Defined in:
lib/pcap2json.rb,
lib/pcap2json/version.rb

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.from_file(filename) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# 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) ⇒ Object



19
20
21
22
23
# 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