Sha256: f3684cada7a8e13d65e3d0ae660c9415b8613224325dbcb2f027dace1c58240e

Contents?: true

Size: 1.19 KB

Versions: 25

Compression:

Stored size: 1.19 KB

Contents

module Facter::NetMask
  def self.get_netmask
    netmask = nil;
    ipregex = %r{(\d{1,3}\.){3}\d{1,3}}

    ops = nil
    case Facter.value(:kernel)
    when 'Linux'
      ops = {
        :ifconfig => '/sbin/ifconfig',
        :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
        :munge => nil,
      }
    when 'SunOS'
      ops = {
        :ifconfig => '/usr/sbin/ifconfig -a',
        :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s (\w{8})}x,
        :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
      }
    when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
      ops = {
        :ifconfig => '/sbin/ifconfig -a',
        :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s 0x(\w{8})}x,
        :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
      }
    end

    %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line|
      matches = line.match(ops[:regex])
      if !matches.nil?
        if ops[:munge].nil?
          netmask = matches[1]
        else
          netmask = ops[:munge].call(matches[1])
        end
      end
    end
    netmask
  end
end

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
facter-1.6.12 lib/facter/util/netmask.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/facter-1.6.11/lib/facter/util/netmask.rb
facter-1.6.12.rc2 lib/facter/util/netmask.rb
facter-1.6.12.rc1 lib/facter/util/netmask.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/facter-1.6.11/lib/facter/util/netmask.rb
facter-1.6.11 lib/facter/util/netmask.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
facter-1.6.10 lib/facter/util/netmask.rb
facter-1.6.9 lib/facter/util/netmask.rb
facter-1.6.8 lib/facter/util/netmask.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
facter-1.6.7 lib/facter/util/netmask.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
facter-1.6.6 lib/facter/util/netmask.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/util/netmask.rb
facter-1.6.5 lib/facter/util/netmask.rb