class Bifrossht::Target

Attributes

entries[R]
port[R]

Public Class Methods

new(host, port) click to toggle source
# File lib/bifrossht/target.rb, line 9
def initialize(host, port)
  @entries = [host]
  @port = port.to_i
end

Public Instance Methods

host() click to toggle source
# File lib/bifrossht/target.rb, line 24
def host
  @entries.last
end
ip() click to toggle source
# File lib/bifrossht/target.rb, line 32
def ip
  @ip ||= IPAddr.new host
rescue IPAddr::InvalidAddressError
  nil
end
ip?() click to toggle source
# File lib/bifrossht/target.rb, line 38
def ip?
  !ip.nil?
end
orig_host() click to toggle source
# File lib/bifrossht/target.rb, line 20
def orig_host
  @entries.first
end
resolvable?() click to toggle source
# File lib/bifrossht/target.rb, line 46
def resolvable?
  !resolved_ip.nil?
end
resolved_ip() click to toggle source
# File lib/bifrossht/target.rb, line 42
def resolved_ip
  @resolved_ip ||= resolve_address
end
rewrite(new) click to toggle source
# File lib/bifrossht/target.rb, line 14
def rewrite(new)
  return if new == host

  @entries.push(new)
end
to_s() click to toggle source
# File lib/bifrossht/target.rb, line 28
def to_s
  host
end

Private Instance Methods

resolve_address() click to toggle source
# File lib/bifrossht/target.rb, line 52
def resolve_address
  return ip if ip?

  record = Resolv.getaddress(host)
  return nil unless record

  IPAddr.new(record)
rescue Resolv::ResolvError
  nil
rescue IPAddr::InvalidAddressError
  nil
end