Module: ScanDB::Runner
- Defined in:
- lib/scandb/runner.rb
Class Method Summary collapse
-
.command_line(args) ⇒ Object
The command-line runner.
Class Method Details
.command_line(args) ⇒ Object
The command-line runner.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/scandb/runner.rb', line 35 def Runner.command_line(args) = OpenStruct.new .log = {} opts = OptionParser.new do |opts| opts. = 'usage: scandb [-v] [-l FILE] [-d URI] [--import-nmap FILE | -L | -p PORT | -s NAME]' opts.on('-l','--log FILE','The FILE to use for logging Database activity.','Defaults to ~/.scandb/database.log') do |file| .log[:path] = file end opts.on('--log-level LEVEL','Specifies the log-level.','Defaults to info') do |level| .log[:level] = level.to_sym end opts.on('--log-stdout','Send log messages to stdout') do .log[:stream] = STDOUT end opts.on('--disable-log','Alias for --log-level off') do .log[:level] = :off end opts.on('-d','--database URI','The URI for the Database.') do |uri| .database = uri end opts.on('--import-nmap FILE','Import a Nmap XML scan file') do |file| .import = :nmap .import_file = file end opts.on('-L','--list-hosts','List all hosts within ScanDB') do .list_hosts = true end opts.on('-p','--with-port PORT','List hosts with the specified open PORT') do |port| .with_port = port.to_i end opts.on('--with-open-ports','List hosts with open ports') do .with_port_status = :open end opts.on('--with-filtered-ports','List hosts with filtered ports') do .with_port_status = :filtered end opts.on('--with-closed-ports','List hosts with closed ports') do .with_port_status = :closed end opts.on('-s','--with-service NAME','List hosts with the specified service') do |name| .with_service = name end opts.on('--export-yaml FILE','Exports hosts as a YAML file') do |path| .export = :yaml .export_path = path end opts.on('--export-xml FILE','Exports hosts as a XML file') do |path| .export = :xml .export_path = path end opts.on('-v','--verbose','Increase verbosity of output') do .verbose = true end opts.on('-V','--version','Print ScanDB version and exit') do puts ScanDB::Version exit end opts.on('-h','--help','This cruft') do puts opts exit end end opts.parse!(args) unless .log.empty? Database.setup_log(.log) end Database.setup(.database || Database.config) if .import case .import when :nmap then hosts = Nmap.import_xml(.import_file) do |host| if .verbose puts ">>> Imported #{host.ip}" end end case hosts when 0 puts "No hosts where imported." when 1 puts "Imported #{hosts} host." else puts "Imported #{hosts} hosts." end end else if .with_port hosts = Port.all(:number => .with_port).scanned(:status => :open).host elsif .with_service hosts = Service.all(:name.like => "%#{.with_service}%").scanned(:status => :open).host else hosts = Host.all end if .export File.open(.export_path,'w') do |output| case .export when :yaml output.write(hosts.to_yaml) when :xml output.write(hosts.to_xml) end end else hosts.each do |host| if .verbose print "[ #{host} ]\n\n" unless host.names.empty? puts ' Host names:' host.names.each do |name| puts " #{name}" end print "\n" end unless host.os_class_guesses.empty? puts ' OS Classes:' host.os_class_guesses.each do |guess| puts " #{guess}" end print "\n" end unless host.os_match_guesses.empty? puts ' OS Matches:' host.os_match_guesses.each do |guess| puts " #{guess}" end print "\n" end unless host.scanned_ports.empty? puts " Scanned Ports:" host.scanned_ports.each do |scanned_port| puts " #{scanned_port}" end print "\n" end else puts host end end end end return true end |