summaryrefslogtreecommitdiffstats
path: root/lib/facter/arp.rb
blob: 383fb48634156b42130a9761c2e315116a7f01de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'facter/util/ip'

Facter.add(:arp) do
  confine :kernel => :linux
  setcode do
    output = Facter::Util::Resolution.exec('arp -a')
    if not output.nil?
      arp = ""
      output.each_line do |s|
        if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/
          arp = $1.downcase
          break # stops on the first match
        end
      end
    end
    "fe:ff:ff:ff:ff:ff" == arp ? arp : nil
  end
end

Facter::Util::IP.get_interfaces.each do |interface|
  Facter.add("arp_" + Facter::Util::IP.alphafy(interface)) do
    confine :kernel => :linux
    setcode do
      arp = Facter::Util::IP.get_arp_value(interface)
      "fe:ff:ff:ff:ff:ff" == arp ? arp : nil
    end
  end
end