module PcaprubHelper
helper module for pcaprub
helper module for pcaprub
helper module for pcaprub
Constants
- DATE
- VERSION
Attributes
cap[R]
filter[RW]
interface[RW]
last_cap[R]
promisc[RW]
snaplen[RW]
timeout[RW]
url_filter[RW]
Public Class Methods
capture_this() { || ... }
click to toggle source
# File lib/pcaprub_helper.rb, line 15 def capture_this build_capture yield @last_cap = parse_capture destroy_capture end
configure() { |self| ... }
click to toggle source
# File lib/pcaprub_helper.rb, line 11 def configure yield self end
look_up_device()
click to toggle source
# File lib/pcaprub_helper.rb, line 46 def look_up_device PCAPRUB::Pcap.lookupdev rescue PCAPRUB::BindingError puts "lookupdev : no suitable device found, defaulting to 'en0'" 'en0' end
verify_path_string(*args)
click to toggle source
# File lib/pcaprub_helper.rb, line 34 def verify_path_string(*args) return false unless @last_cap @last_cap.each do |packet| args.each do |value| return false unless packet =~ path_string_validator(value) end end true end
verify_query_string(**kwargs)
click to toggle source
# File lib/pcaprub_helper.rb, line 22 def verify_query_string(**kwargs) return false unless @last_cap @last_cap.each do |packet| kwargs.each do |key, value| return false unless packet =~ query_string_validator(key, value) end end true end
Private Class Methods
build_capture()
click to toggle source
# File lib/pcaprub_helper.rb, line 63 def build_capture @cap = PCAPRUB::Pcap.open_live(@interface, @snaplen, @promisc, @timeout) @cap.setfilter(@filter || '') end
destroy_capture()
click to toggle source
# File lib/pcaprub_helper.rb, line 68 def destroy_capture @cap.close @cap = nil end
parse_capture()
click to toggle source
# File lib/pcaprub_helper.rb, line 73 def parse_capture packets = [] loop do packet = @cap.next break unless packet next unless filter(packet) packets << URI.decode(packet) end packets end
path_string_validator(value)
click to toggle source
# File lib/pcaprub_helper.rb, line 59 def path_string_validator(value) %r{\/#{value}\/i} end
query_string_validator(key, value)
click to toggle source
# File lib/pcaprub_helper.rb, line 55 def query_string_validator(key, value) /(\&|\?)#{key}[\[\]]{0,2}=#{value}(\&|\s)/i end