From 8ef11a7b494b16446f324af9903ca7c729db03f2 Mon Sep 17 00:00:00 2001 From: Justin Seely Date: Sat, 9 Sep 2017 03:55:34 +0000 Subject: Check all associated host addresses for FQDNs instead of just the last Signed-off-by: Justin Seely --- lib/ohai/plugins/hostname.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index 0f103c5d..15d19091 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -173,9 +173,20 @@ Ohai.plugin(:Hostname) do if info.first =~ /.+?\.(.*)/ fqdn info.first else - # host is not in dns. optionally use: - # C:\WINDOWS\system32\drivers\etc\hosts - fqdn Socket.gethostbyaddr(info.last).first + #host is not in dns. optionally use: + #C:\WINDOWS\system32\drivers\etc\hosts + found_fqdn = false + info[3..info.length].reverse.each do |addr| + hostent = Socket.gethostbyaddr(addr) + if hostent.first =~ /.+?\.(.*)/ + fqdn hostent.first + found_fqdn = true + break + end + end + if !found_fqdn + fqdn info.first + end end domain collect_domain end -- cgit v1.2.1