Class: LifxDash::Capturer
- Inherits:
-
Object
- Object
- LifxDash::Capturer
- Defined in:
- lib/lifx_dash/capturer.rb
Constant Summary collapse
- PACKET_FILTER =
Berkeley Packet filter for Amazon Dash buttons
- most dash buttons broadcast a DHCP request from 0.0.0.0 - for more details see https://github.com/ide/dash-button/issues/36
"udp and src port 68 and dst port 67 and udp[247:4] == 0x63350103 and src host 0.0.0.0"
Instance Attribute Summary collapse
-
#iface ⇒ Object
readonly
Returns the value of attribute iface.
Instance Method Summary collapse
-
#initialize(network_iface_id) ⇒ Capturer
constructor
A new instance of Capturer.
- #listen(&block) ⇒ Object
Constructor Details
#initialize(network_iface_id) ⇒ Capturer
Returns a new instance of Capturer.
16 17 18 |
# File 'lib/lifx_dash/capturer.rb', line 16 def initialize(network_iface_id) @iface = network_iface_id end |
Instance Attribute Details
#iface ⇒ Object (readonly)
Returns the value of attribute iface.
14 15 16 |
# File 'lib/lifx_dash/capturer.rb', line 14 def iface @iface end |
Instance Method Details
#listen(&block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lifx_dash/capturer.rb', line 20 def listen(&block) # examine packets on the stream capturer.stream.each do |packet| if PacketFu::IPPacket.can_parse?(packet) pkt = PacketFu::IPPacket.parse(packet) # only consider the first (early ip ids) even packet sent # since dhcp often sends 2 packets in a quick burst if pkt && pkt.ip_id < 5 && (pkt.ip_id % 2) == 0 puts pkt.inspect mac = PacketFu::EthHeader.str2mac(pkt.eth_src) block.call(pkt, mac) if block end end end end |