Module: Macmap

Defined in:
lib/macmap.rb

Class Method Summary collapse

Class Method Details

.map_iface_to_ip(str) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/macmap.rb', line 2

def self.map_iface_to_ip(str)
  regexes = {
    :new_iface => /^\S+([a-zA-Z]+[0-9]*)[:]?/,
    :new_ip => /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
  }

  out = {}
  str.split("\n").each do |line|
    if m = line.match(regexes[:new_iface])#/^\S+ \((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([a-zA-Z0-9\.\:\-]+) \[(\w+)\]/
      @current_interface = m.to_s.gsub(/:/, "")
    end
    if @current_interface
      if i = line.match(regexes[:new_ip])
        out[@current_interface] = i.to_s
      end
    end
  end
  out
end