class RushButton::DashCapture

Constants

REFER_URL
VENDOR_NAME

Public Class Methods

new(iface) click to toggle source
# File lib/rush_button/dash_capture.rb, line 11
def initialize iface
  @capture = Capture.new(iface: iface, filter: Protocol::ARP, promisc: true)
end

Public Instance Methods

capture() click to toggle source
# File lib/rush_button/dash_capture.rb, line 15
def capture
  not_amazons = []
  loop do
    packet = @capture.next
    unless packet
      sleep 1
      next
    end
    if ARPPacket.can_parse? packet
      src_mac = ARPPacket.parse(packet).eth_src_readable
      puts "captured MAC: #{src_mac}" if $DEBUG
      if not_amazons.include? src_mac
        next
      end
      vendor_mac = (src_mac.split(":"))[0..2].join(":")
      puts "refer to #{REFER_URL+vendor_mac}..." if $DEBUG 
      vendor_name = Net::HTTP.get URI.parse(REFER_URL+vendor_mac)
      puts "vendor name: #{vendor_name}" if $DEBUG
      if vendor_name == VENDOR_NAME
        puts "this is Amazon!" if $DEBUG
        return src_mac
      else
        not_amazons << src_mac
      end
    end
  end
end