Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as Ruby by Brian Gallew ( 16 years ago )
#facter/cprt_ipaddresses.rb
Facter.add(:cprt_ipaddresses) do
    confine :kernel => :linux
    setcode do
        ip = []
        output = %x{/sbin/ifconfig}

        output.split(/^\S/).each { |str|
            if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
                tmp = $1
                unless tmp =~ /127\./ or tmp == "0.0.0.0"
                    ip << tmp 
                end
            end
        }

        ip.join(',')
    end
end

Facter.add(:cprt_ipaddresses) do
    confine :kernel => %w{FreeBSD OpenBSD SunOS solaris NetBSD darwin}
    setcode do
        ip = []
        output = %x{/sbin/ifconfig -a}

        output.split(/^\S/).each { |str|
            if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
                tmp = $1
                unless tmp =~ /127\./ or tmp == "0.0.0.0"
                    ip << tmp
                end
            end
        }

        ip.join(',')
    end
end

Facter.add(:cprt_ipaddresses) do
    confine :kernel => %w{AIX}
    setcode do
        ip = []
        output = %x{/usr/sbin/ifconfig -a}

        output.split(/^\S/).each { |str|
            if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
                tmp = $1
                unless tmp =~ /127\./ or tmp == "0.0.0.0"
                    ip << tmp
                end
            end
        }

        ip.join(',')
    end
end

Facter.add(:cprt_ipaddresses) do
    confine :kernel => %w{windows}
    setcode do
        ip = []
        output = %x{ipconfig}

        output.split(/^\S/).each { |str|
            if str =~ /IP Address.*: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
                tmp = $1
                unless tmp =~ /127\./ or tmp == "0.0.0.0"
                    ip << tmp
                end
            end
        }
        ip.join(',')
    end
end

 

Revise this Paste

Your Name: Code Language: