Class: Puffy::Resolver
- Inherits:
-
Object
- Object
- Puffy::Resolver
- Includes:
- Singleton
- Defined in:
- lib/puffy/resolver.rb
Overview
DNS resolution class.
Instance Method Summary collapse
-
#resolv(hostname, address_family = nil) ⇒ Array<IPAddr>
Resolve
hostnameand return an Array of IPAddr. - #resolv_apt_mirror(url) ⇒ Object
-
#resolv_srv(service) ⇒ Array<Hash>
Resolve the SRV record for
serviceand return its target and port.
Instance Method Details
#resolv(hostname, address_family = nil) ⇒ Array<IPAddr>
Resolve hostname and return an Array of IPAddr.
25 26 27 28 29 30 31 |
# File 'lib/puffy/resolver.rb', line 25 def resolv(hostname, address_family = nil) if hostname.is_a?(IPAddr) resolv_ipaddress(hostname, address_family) else resolv_hostname(hostname, address_family) end end |
#resolv_apt_mirror(url) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puffy/resolver.rb', line 46 def resolv_apt_mirror(url) res = [] http_url = url.sub(%r{^mirror(\+http)?://}, 'http://') res << parse_url(http_url) URI.parse(http_url).open do |document| document.each_line do |line| res << parse_url(line) end end res end |
#resolv_srv(service) ⇒ Array<Hash>
Resolve the SRV record for service and return its target and port.
41 42 43 44 |
# File 'lib/puffy/resolver.rb', line 41 def resolv_srv(service) proto = service.split('.')[1][1..-1].to_sym @dns.getresources(service, Resolv::DNS::Resource::IN::SRV).collect { |r| { host: r.target.to_s, port: r.port, proto_hint: proto } }.sort end |