Class: MetaBridge::ARP

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/meta_bridge/arp.rb

Constant Summary collapse

IP_REGEX =
/(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)/i
MAC_REGEX =
/([0-9A-F]{2}[:-]){5}([0-9A-F]{2})/i

Instance Method Summary collapse

Methods included from Command

#run

Instance Method Details

#connectionsObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/meta_bridge/arp.rb', line 9

def connections
  connections = []
  run('arp -i eth1 -a') do |out|
    while line = out.gets
      connections << parse_arp_line(line)
    end
  end

  connections
end

#parse_arp_line(line) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/meta_bridge/arp.rb', line 20

def parse_arp_line(line)
  hsh = {}
  
  line.split.each do |token|
    hsh[:ip] = $1 if token =~ IP_REGEX
    hsh[:mac] = token if token =~ MAC_REGEX
  end

  hsh
end