lib/facter/ipaddress.rb in facter-1.7.2 vs lib/facter/ipaddress.rb in facter-1.7.3.rc1

- old
+ new

@@ -31,15 +31,17 @@ output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"]) if output regexp = /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ output.split("\n").each do |line| match = regexp.match(line) - if match - break match[1] unless /^127/.match(match[1]) + if match and not /^127\./.match(match[1]) + ip = match[1] + break end end end + ip end end Facter.add(:ipaddress) do confine :kernel => %w{FreeBSD OpenBSD Darwin DragonFly} @@ -102,11 +104,21 @@ end Facter.add(:ipaddress) do confine :kernel => %w{windows} setcode do - require 'socket' - IPSocket.getaddress(Socket.gethostname) + require 'facter/util/ip/windows' + ipaddr = nil + + adapters = Facter::Util::IP::Windows.get_preferred_ipv4_adapters + adapters.find do |nic| + nic.IPAddress.any? do |addr| + ipaddr = addr if Facter::Util::IP::Windows.valid_ipv4_address?(addr) + ipaddr + end + end + + ipaddr end end Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do setcode do