module Async::DNS::System
This module encapsulates system dependent name lookup functionality.
Constants
- HOSTS
- RESOLV_CONF
Public Class Methods
hosts_path()
click to toggle source
# File lib/async/dns/system.rb, line 33 def self.hosts_path if RUBY_PLATFORM =~ /mswin32|mingw|bccwin/ Win32::Resolv.get_hosts_path else HOSTS end end
nameservers()
click to toggle source
Get a list of standard nameserver connections which can be used for querying any standard servers that the system has been configured with. There is no equivalent facility to use the `hosts` file at present.
# File lib/async/dns/system.rb, line 134 def self.nameservers nameservers = [] if File.exist? RESOLV_CONF nameservers = parse_resolv_configuration(RESOLV_CONF) elsif defined?(Win32::Resolv) and RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/ search, nameservers = Win32::Resolv.get_resolv_info end return standard_connections(nameservers) end
parse_resolv_configuration(path)
click to toggle source
# File lib/async/dns/system.rb, line 102 def self.parse_resolv_configuration(path) nameservers = [] File.open(path) do |file| file.each do |line| # Remove any comments: line.sub!(/[#;].*/, '') # Extract resolv.conf command: keyword, *args = line.split(/\s+/) case keyword when 'nameserver' nameservers += args end end end return nameservers end
standard_connections(nameservers)
click to toggle source
# File lib/async/dns/system.rb, line 122 def self.standard_connections(nameservers) connections = [] nameservers.each do |host| connections << [:udp, host, 53] connections << [:tcp, host, 53] end return connections end