module Namecheap::Dynamic::Dns::Network
This module is designed for all network related functions.
Public Instance Methods
an_ip?(host_name)
click to toggle source
# File lib/namecheap/dynamic/dns/network.rb, line 29 def an_ip?(host_name) IPAddress.valid?(host_name) end
external_ip()
click to toggle source
# File lib/namecheap/dynamic/dns/network.rb, line 8 def external_ip self.ip = nil begin self.ip = open('http://whatismyip.akamai.com').read rescue StandardError => err logger.warn('Failed to retrieve external I.P.') logger.debug(err) end end
extract_ip(ip_or_host)
click to toggle source
# File lib/namecheap/dynamic/dns/network.rb, line 33 def extract_ip(ip_or_host) if an_ip?(ip_or_host) ip_or_host else host_to_ip(ip_or_host) end end
got_external_ip?()
click to toggle source
# File lib/namecheap/dynamic/dns/network.rb, line 50 def got_external_ip? return true unless ip.nil? logger.error('No external ip detected. Aborting!!') false end
host_ip_match?(domain, target, target_ip)
click to toggle source
# File lib/namecheap/dynamic/dns/network.rb, line 41 def host_ip_match?(domain, target, target_ip) host = %w(@ *).include?(target) ? domain : [target, domain].join('.') host_to_ip(host) == target_ip end
host_to_ip(host_name)
click to toggle source
# File lib/namecheap/dynamic/dns/network.rb, line 18 def host_to_ip(host_name) begin Resolv.getaddress(host_name) rescue StandardError => err logger.fatal('Failed to retrieve host I.P. address') logger.debug("Host Name: #{hostname}") logger.error(err) host_name end end
valid_domain?(target_domain)
click to toggle source
# File lib/namecheap/dynamic/dns/network.rb, line 46 def valid_domain?(target_domain) !target_domain.match(/\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,16}\z/ix).nil? end