Sha256: 09762c1888d914e3af256e001284b7753dec12b81cb2c03ce7106d8bc94e3e78

Contents?: true

Size: 1.97 KB

Versions: 12

Compression:

Stored size: 1.97 KB

Contents

# Fact: macaddress
#
# Purpose:
#
# Resolution:
#
# Caveats:
#

require 'facter/util/macaddress'

Facter.add(:macaddress) do
  confine :kernel => %w{SunOS Linux GNU/kFreeBSD}
  setcode do
    ether = []
    output = Facter::Util::Resolution.exec("/sbin/ifconfig -a")
    output.each_line do |s|
      ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
    end
    Facter::Util::Macaddress.standardize(ether[0])
  end
end

Facter.add(:macaddress) do
  confine :operatingsystem => "Solaris"
  setcode do
    ether = []
    output = Facter::Util::Resolution.exec("/usr/bin/netstat -np")
    output.each_line do |s|
      ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/
    end
    Facter::Util::Macaddress.standardize(ether[0])
  end
end

Facter.add(:macaddress) do
  confine :operatingsystem => %w{FreeBSD OpenBSD DragonFly}
  setcode do
    ether = []
    output = Facter::Util::Resolution.exec("/sbin/ifconfig")
    output.each_line do |s|
      if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
        ether.push($1)
      end
    end
    Facter::Util::Macaddress.standardize(ether[0])
  end
end

Facter.add(:macaddress) do
  confine :kernel => :darwin
  setcode { Facter::Util::Macaddress::Darwin.macaddress }
end

Facter.add(:macaddress) do
  confine :kernel => %w{AIX}
  setcode do
    ether = []
    ip = nil
    output = %x{/usr/sbin/ifconfig -a}
    output.each_line do |str|
      if str =~ /([a-z]+\d+): flags=/
        devname = $1
        unless devname =~ /lo0/
          output2 = %x{/usr/bin/entstat #{devname}}
          output2.each_line do |str2|
            if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
              ether.push($1)
            end
          end
        end
      end
    end
    Facter::Util::Macaddress.standardize(ether[0])
  end
end

Facter.add(:macaddress) do
  confine :kernel => %w(windows)
  setcode do
    Facter::Util::Macaddress::Windows.macaddress
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
facter-1.6.12 lib/facter/macaddress.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/facter-1.6.11/lib/facter/macaddress.rb
facter-1.6.12.rc2 lib/facter/macaddress.rb
facter-1.6.12.rc1 lib/facter/macaddress.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/facter-1.6.11/lib/facter/macaddress.rb
facter-1.6.11 lib/facter/macaddress.rb
facter-1.6.10 lib/facter/macaddress.rb
facter-1.6.9 lib/facter/macaddress.rb
facter-1.6.8 lib/facter/macaddress.rb
facter-1.6.7 lib/facter/macaddress.rb
facter-1.6.6 lib/facter/macaddress.rb
facter-1.6.5 lib/facter/macaddress.rb