Puppet Function: nslookup
- Defined in:
- lib/puppet/parser/functions/nslookup.rb
- Function type:
- Ruby 3.x API
Overview
Lookup a hostname and return its ip addresses
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppet/parser/functions/nslookup.rb', line 15 newfunction(:nslookup, :type => :rvalue, :doc => <<-EOS Lookup a hostname and return its ip addresses EOS ) do |vals| hostname, type = vals raise(ArgumentError, 'Must specify a hostname') unless hostname type = 'AAAA' unless type require 'ipaddr' if (ip = IPAddr.new(hostname) rescue nil) if (ip.ipv6? and type == 'AAAA') or (ip.ipv4? and type != 'AAAA') return hostname else return [] end end typeConst = Resolv::DNS::Resource::IN.const_get "#{type.upcase}" out = [] Resolv::DNS.open do |dns| dns.getresources(hostname, typeConst).collect {|r| out << IPAddr::new_ntoh(r.address.address).to_s } end return out end |