Class: RushButton::Server

Inherits:
Object
  • Object
show all
Includes:
PacketFu
Defined in:
lib/rush_button/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(iface) ⇒ Server

Returns a new instance of Server.



6
7
8
9
# File 'lib/rush_button/server.rb', line 6

def initialize iface
  @iface = iface
  @buttons = []
end

Instance Method Details

#add(mac_addr, &block) ⇒ Object



11
12
13
# File 'lib/rush_button/server.rb', line 11

def add mac_addr, &block
  @buttons << DashButton.new(mac_addr).on_press(&block)
end

#startObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/rush_button/server.rb', line 15

def start
  puts "Dash Button capturing..." if $DEBUG
  cap = Capture.new(iface:@iface, filter:Protocol::ARP, promisc:true)
  cap.stream.each do |pkt|
    if ARPPacket.can_parse?(pkt)
      src_mac = ARPPacket.parse(pkt).eth_src_readable
      @buttons.find {|e| e.mac == src_mac}&.press
    end
  end
end