class Ryo::Target

Attributes

domain[R]
uri[R]

Public Class Methods

new(uri) click to toggle source
# File lib/ryo/target.rb, line 8
def initialize(uri)
  @uri = URI.parse(uri)
  @domain = @uri.host
end

Public Instance Methods

fld() click to toggle source
# File lib/ryo/target.rb, line 13
def fld
  @fld ||= String.new.tap do |out|
    removed_tlds_domain = domain.gsub(tlds_regexp, "")
    # test.com => ["test"]
    # dev.test.com => ["dev", "test"]
    parts = removed_tlds_domain.split(".")
    if parts.length == 1 || ip?
      out << domain
    else
      idx = domain.split(".").index(parts.last)
      out << domain.split(".")[idx..-1].join(".")
    end
  end
end
ip() click to toggle source
# File lib/ryo/target.rb, line 28
def ip
  @ip ||= String.new.tap do |out|
    h = Plugin::DNS.new(domain).dig("A")
    out << (h.dig("Answer")&.first&.dig("data") || "N/A")
  end
end

Private Instance Methods

ip?() click to toggle source
# File lib/ryo/target.rb, line 45
def ip?
  IPAddr.new(domain.to_s)
  true
rescue IPAddr::InvalidAddressError => _
  false
end
tlds() click to toggle source
# File lib/ryo/target.rb, line 37
def tlds
  File.readlines(File.expand_path("./aux/tlds.txt", __dir__)).map(&:chomp).compact
end
tlds_regexp() click to toggle source
# File lib/ryo/target.rb, line 41
def tlds_regexp
  Regexp.new tlds.map { |domain| "#{domain.split('.').join('\\.')}$" }.join("|")
end