Module Facter::IPAddress
In: lib/facter/util/ip.rb

Methods

Public Class methods

[Source]

    # File lib/facter/util/ip.rb, line 19
19:     def self.get_all_interface_output
20:         case Facter.value(:kernel)
21:             when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
22:                 output = %x{/sbin/ifconfig -a}
23:             when 'SunOS'
24:                 output = %x{/usr/sbin/ifconfig -a}
25:         end
26:         output
27:     end

[Source]

    # File lib/facter/util/ip.rb, line 41
41:     def self.get_interface_value(interface, label)
42:     
43:     tmp1 = []
44: 
45:     case Facter.value(:kernel)
46:       when 'Linux'
47:        addr = /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
48:        mac  = /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
49:        mask = /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
50:      when 'OpenBSD', 'NetBSD', 'FreeBSD'
51:        addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
52:        mac  = /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
53:        mask = /netmask\s+(\w{10})/
54:     when 'SunOS'
55:        addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
56:        mac  = /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/
57:        mask = /netmask\s+(\w{8})/
58:     end
59: 
60:     case label
61:       when 'ipaddress'
62:        regex = addr
63:       when 'macaddress'
64:        regex = mac
65:       when 'netmask'
66:        regex = mask
67:     end 
68: 
69:     output_int = get_single_interface_output(interface)
70:      
71:       if interface != "lo" && interface != "lo0"
72:         output_int.each { |s|
73:            if s =~ regex
74:                value = $1
75:                if label == 'netmask' && Facter.value(:kernel) == "SunOS"
76:                    value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.') 
77:                end
78:                tmp1.push(value)
79:            end
80:        }
81:       end
82: 
83:       if tmp1 
84:         value = tmp1.shift
85:       end
86: 
87:    end

[Source]

    # File lib/facter/util/ip.rb, line 3
 3:     def self.get_interfaces
 4:     
 5:      int = nil
 6:     
 7:      output =  Facter::IPAddress.get_all_interface_output()
 8: 
 9:      # We get lots of warnings on platforms that don't get an output
10:      # made.
11:      if output
12:          int = output.scan(/^\w+[.:]?\d+/)
13:      else
14:          []
15:      end
16:     
17:     end

[Source]

    # File lib/facter/util/ip.rb, line 29
29:     def self.get_single_interface_output(interface)
30:         output = ""
31:         case Facter.value(:kernel)
32:             when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
33:                     output = %x{/sbin/ifconfig #{interface}}
34:             when 'SunOS'
35:             output = %x{/usr/sbin/ifconfig #{interface}}
36:         end
37:         output
38:     end

[Validate]