Methods

Facter::NetMask

Public Class Methods

get_netmask() click to toggle source
    # File lib/facter/util/netmask.rb, line 2
 2:   def self.get_netmask
 3:     netmask = nil;
 4:     ipregex = %{(\d{1,3}\.){3}\d{1,3}}
 5: 
 6:     ops = nil
 7:     case Facter.value(:kernel)
 8:     when 'Linux'
 9:       ops = {
10:         :ifconfig => '/sbin/ifconfig',
11:         :regex => %{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})},
12:         :munge => nil,
13:       }
14:     when 'SunOS'
15:       ops = {
16:         :ifconfig => '/usr/sbin/ifconfig -a',
17:         :regex => %{\s+ inet \s #{Facter.ipaddress} \s netmask \s (\w{8})},
18:         :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
19:       }
20:     when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
21:       ops = {
22:         :ifconfig => '/sbin/ifconfig -a',
23:         :regex => %{\s+ inet \s #{Facter.ipaddress} \s netmask \s 0x(\w{8})},
24:         :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
25:       }
26:     end
27: 
28:     %{#{ops[:ifconfig]}}.split(/\n/).collect do |line|
29:       matches = line.match(ops[:regex])
30:       if !matches.nil?
31:         if ops[:munge].nil?
32:           netmask = matches[1]
33:         else
34:           netmask = ops[:munge].call(matches[1])
35:         end
36:       end
37:     end
38:     netmask
39:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.