Sha256: dff0d44889696420c439c35cee01f6cb3a71d1b831753721cd148f1b02455b2a

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 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 2>/dev/null',
        :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

11 entries across 11 versions & 2 rubygems

Version Path
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/facter-1.6.17/lib/facter/util/netmask.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/facter-1.6.17/lib/facter/util/netmask.rb
facter-1.6.17 lib/facter/util/netmask.rb
facter-1.6.17.rc1 lib/facter/util/netmask.rb
facter-1.6.16 lib/facter/util/netmask.rb
facter-1.6.15 lib/facter/util/netmask.rb
facter-1.6.15.rc1 lib/facter/util/netmask.rb
facter-1.6.14 lib/facter/util/netmask.rb
facter-1.6.14.rc1 lib/facter/util/netmask.rb
facter-1.6.13 lib/facter/util/netmask.rb
facter-1.6.13.rc1 lib/facter/util/netmask.rb