# # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com) # # This file is part of Ronin. # # Ronin is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ronin is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ronin. If not, see . # require 'ronin/ui/cli/resources_command' require 'ronin/host_name' module Ronin module UI module CLI module Commands # # The `ronin-hosts` command. # class Hosts < ResourcesCommand model HostName query_option :with_ips, :type => Array, :flag => '-I', :usage => 'IP [...]' query_option :with_ports, :type => Array[Integer], :flag => '-p', :usage => 'PORT [...]' query_option :domain, :type => String, :flag => '-D', :usage => 'DOMAIN' query_option :tld, :type => String, :flag => '-T', :usage => 'TLD' option :list, :type => true, :default => true, :flag => '-l' option :lookup, :type => String, :flag => '-L', :usage => 'IP' option :import, :type => String, :flag => '-i', :usage => 'FILE' # # Queries the {HostName} model. # # @since 1.0.0 # def execute if lookup? lookup(@lookup) else super end end protected # # Looks up an IP address. # # @param [String] ip # The IP address to look up. # # @since 1.0.0 # def lookup(ip) print_info "Looking up #{ip} ..." HostName.lookup(ip).each do |host| print_info " #{host}" end print_info "Looked up #{ip}" end # # Prints a host name. # # @param [HostName] host # The host name to print. # # @since 1.0.0 # def print_resource(host) return super(host) unless verbose? print_title host.address indent do if (org = host.organization) print_hash 'Organization' => org end if (last_scanned_at = host.last_scanned_at) print_hash 'Last Scanned' => last_scanned_at end unless host.ip_addresses.empty? print_array host.ip_addresses, :title => 'IP Addresses' end unless host.open_ports.empty? print_section 'Open Ports' do host.open_ports.each do |port| if port.service puts "#{port}\t#{port.service}" else puts port end end end end unless host.email_addresses.empty? print_array host.email_addresses, :title => 'Email Addresses' end unless host.urls.empty? print_array host.urls, :title => 'URLs' end end end end end end end end