summaryrefslogtreecommitdiffstats
path: root/lib/facter/ipaddress.rb
diff options
context:
space:
mode:
authorDavid Schmitt <david@dasz.at>2010-06-14 17:05:20 +0200
committerJames Turnbull <james@lovedthanlost.net>2010-06-15 01:25:36 +1000
commit83b3ea6abbd1d382a6738fa731f9f7409867e135 (patch)
tree11158a2f610dba94c839809d5ea86ce5d3de6188 /lib/facter/ipaddress.rb
parentffcae46df5d5336995348544139540c0e564ae2e (diff)
downloadfacter-83b3ea6abbd1d382a6738fa731f9f7409867e135.tar.gz
facter-83b3ea6abbd1d382a6738fa731f9f7409867e135.tar.xz
facter-83b3ea6abbd1d382a6738fa731f9f7409867e135.zip
Fixed #3393 - Updates to Facter for MS Windows
This patch is originally by Daniel Berger <djberg96@gmail.com>, I changed using Facter.value instead of repeatedly testing Config['host_os'], removed Resolution::which, and fixed the specs. Thanks to Paul Nasrat for helping with cross-platform debugging. Signed-off-by: David Schmitt <david@dasz.at>
Diffstat (limited to 'lib/facter/ipaddress.rb')
-rw-r--r--lib/facter/ipaddress.rb31
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
index dd0d418..7c62aa1 100644
--- a/lib/facter/ipaddress.rb
+++ b/lib/facter/ipaddress.rb
@@ -111,30 +111,25 @@ end
Facter.add(:ipaddress) do
confine :kernel => %w{windows}
- setcode do
- ip = nil
- 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\./
- ip = tmp
- break
- end
- end
- }
- ip
- end
+ require 'socket'
+ IPSocket.getaddress(Socket.gethostname)
end
Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
setcode do
- require 'resolv'
-
+ if Facter.value(:kernel) == 'windows'
+ require 'win32/resolv'
+ else
+ require 'resolv'
+ end
+
begin
if hostname = Facter.value(:hostname)
- ip = Resolv.getaddress(hostname)
+ if Facter.value(:kernel) == 'windows'
+ ip = Win32::Resolv.get_resolv_info.last[0]
+ else
+ ip = Resolv.getaddress(hostname)
+ end
unless ip == "127.0.0.1"
ip
end