Sha256: f0cf29c07b1887e9332f7ea4e41b10276fc0dec728b591ea3e1e6149f182f97b
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
# encoding : utf-8 require 'diy/ext/capture_wrapper' module DIY class Live def initialize(device_name) DIY::Logger.info( "Initialize Live: #{device_name}" ) @live = FFI::PCap::Live.new(:dev=>device_name, :handler => FFI::PCap::CopyHandler, :promisc => true) DIY::Logger.info( "Listen on: #{net} " ) @running = false @live.non_blocking= true end attr_reader :live # 发包 def inject(packet_str) @live.send_packet(packet_str) end alias send_packet inject def loop(&block) @running = true while @running do @live.dispatch do |this, pkt| next unless pkt block.call(this, pkt) end sleep 0.1 end DIY::Logger.debug "stopped loop recv..." end def set_filter(reg) @live.set_filter(reg) end def break DIY::Logger.debug "stopping loop recv..." @running = false end def net @live.network + " / " + @live.netmask end end # end of class Live end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
DIY-pcap-0.3.5 | lib/diy/live.rb |
DIY-pcap-0.3.4 | lib/diy/live.rb |