Skip to content

Commit

Permalink
Check all associated host addresses for FQDNs instead of just the last
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Seely <justin.seely@gmail.com>
  • Loading branch information
jseely committed Sep 9, 2017
1 parent 855ab64 commit f9f40e9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/ohai/plugins/hostname.rb
Expand Up @@ -175,13 +175,17 @@ def collect_hostname
else
#host is not in dns. optionally use:
#C:\WINDOWS\system32\drivers\etc\hosts
if info.last.length == 4
#If the last ip addr in the list is IPv4 use that
fqdn Socket.gethostbyaddr(info.last).first
else
#If the last ip addr in the list is IPv6 use the one before it
#This is a workaround because the underlying winsock calls only return the machine name when given an IPv6 address
fqdn Socket.gethostbyaddr(info[info.length - 2]).first
found_fqdn = false
for addr in info[3..info.length].reverse
hostent = Socket.gethostbyaddr(addr).first
if hostent.first =~ /.+?\.(.*)/
fqdn hostent.first
found_fqdn = true
break
end
end
if !found_fqdn
fqdn info.first
end
end
domain collect_domain
Expand Down

0 comments on commit f9f40e9

Please sign in to comment.