summaryrefslogtreecommitdiffstats
path: root/lib/facter/iphostnumber.rb
blob: cddaadd1e663ed1f8179cfb77620ecf421487426 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Fact: iphostnumber
#
# Purpose: On selected versions of Darwin, returns the host's IP address.
#
# Resolution:
#   Uses either the scutil program to get the localhost name, or parses output
#   of ifconfig for a MAC address.
#
# Caveats:
#

Facter.add(:iphostnumber) do
    confine :kernel => :darwin, :kernelrelease => "R6"
    setcode do
        %x{/usr/sbin/scutil --get LocalHostName}
    end
end
Facter.add(:iphostnumber) do
    confine :kernel => :darwin, :kernelrelease => "R6"
    setcode do
        ether = nil
        output = %x{/sbin/ifconfig}

        output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
        ether = $1

        ether
    end
end