@@ -73,10 +73,10 @@ def shodan_query(query, apikey, page)
73
73
74
74
# save output to file
75
75
def save_output ( data )
76
- f = ::File . open ( datastore [ 'OUTFILE' ] , 'wb' )
77
- f . write ( data )
78
- f . close
79
- print_status ( "Save results in #{ datastore [ 'OUTFILE' ] } " )
76
+ ::File . open ( datastore [ 'OUTFILE' ] , 'wb' ) do | f |
77
+ f . write ( data )
78
+ print_status ( "Saved results in #{ datastore [ 'OUTFILE' ] } " )
79
+ end
80
80
end
81
81
82
82
# Check to see if api.shodan.io resolves properly
@@ -141,9 +141,14 @@ def run
141
141
142
142
# Organize results and put them into the table and database
143
143
page = 1
144
+ #my_filter = Regexp.new(datastore['FILTER'], true) if datastore['FILTER']
144
145
my_filter = datastore [ 'FILTER' ]
145
- for i in page ..tpages
146
- next if results [ i ] . nil? || results [ i ] [ 'matches' ] . nil?
146
+ print_status ( "page: #{ page } " )
147
+ print_status ( "tpages: #{ tpages } " )
148
+ pages = page ..tpages
149
+ pages . each do |i |
150
+ next if results [ i ] . nil? or results [ i ] [ 'matches' ] . nil?
151
+ print_status ( "i is: #{ i } " )
147
152
results [ i ] [ 'matches' ] . each do |host |
148
153
149
154
city = host [ 'location' ] [ 'city' ] || 'N/A'
@@ -164,20 +169,21 @@ def run
164
169
:info => 'Added from Shodan'
165
170
) if datastore [ 'DATABASE' ]
166
171
167
- if ip =~ /#{ my_filter } / ||
168
- city =~ /#{ my_filter } /i ||
169
- country =~ /#{ my_filter } /i ||
170
- hostname =~ /#{ my_filter } /i ||
171
- data =~ /#{ my_filter } /i
172
- # Unfortunately we cannot display the banner properly,
173
- # because it messes with our output format
174
- tbl << [ "#{ ip } :#{ port } " , city , country , hostname ]
172
+ if ip =~ /#{ my_filter } / or
173
+ city =~ /#{ my_filter } /i or
174
+ country =~ /#{ my_filter } /i or
175
+ hostname =~ /#{ my_filter } /i or
176
+ data =~ /#{ my_filter } /i
177
+ # Unfortunately we cannot display the banner properly,
178
+ # because it messes with our output format
179
+ tbl << [ "#{ ip } :#{ port } " , city , country , hostname ]
175
180
end
176
181
end
177
182
end
178
183
179
184
# Show data and maybe save it if needed
180
- print_line ( "\n #{ tbl . to_s } " )
181
- save_output ( tbl . to_s ) if not datastore [ 'OUTFILE' ] . nil?
185
+ print_line
186
+ print_line ( "#{ tbl } " )
187
+ save_output ( tbl ) if not datastore [ 'OUTFILE' ] . nil?
182
188
end
183
189
end
0 commit comments