Class: Ronin::UI::CLI::Commands::Hosts

Inherits:
ResourcesCommand show all
Defined in:
lib/ronin/ui/cli/commands/hosts.rb

Overview

The ronin-hosts command.

Instance Method Summary collapse

Methods inherited from ResourcesCommand

model, #print_resources

Methods inherited from ModelCommand

each_query_option, model, #query, query_option, query_options, #setup

Methods inherited from Ronin::UI::CLI::Command

banner, command_name, #indent, inherited, #initialize, #print_array, #print_exception, #print_hash, #print_section, #print_title, #puts, run, #setup

Constructor Details

This class inherits a constructor from Ronin::UI::CLI::Command

Instance Method Details

#executeObject

Queries the HostName model.

Since:

  • 1.0.0


67
68
69
70
71
72
73
# File 'lib/ronin/ui/cli/commands/hosts.rb', line 67

def execute
  if options[:lookup]
    lookup options[:lookup]
  else
    super
  end
end

#lookup(ip) ⇒ Object (protected)

Looks up an IP address.

Parameters:

  • ip (String)

    The IP address to look up.

Since:

  • 1.0.0


85
86
87
88
89
90
91
92
93
# File 'lib/ronin/ui/cli/commands/hosts.rb', line 85

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.

Parameters:

  • host (HostName)

    The host name to print.

Since:

  • 1.0.0


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ronin/ui/cli/commands/hosts.rb', line 103

def print_resource(host)
  return super(host) unless options.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