fofa 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/fofacli +30 -6
  3. data/lib/fofa/version.rb +4 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22c81fe840d8bb06a94f9eef98e78a64fe6123ec
4
- data.tar.gz: fb125f15801160dfb5913a28c5d5c35967fd03ea
3
+ metadata.gz: 87d0a961aecc981843e098178b7c3fc2c70c14f7
4
+ data.tar.gz: 10df9f621ee857e19eb9a31ea5c488fe71895135
5
5
  SHA512:
6
- metadata.gz: 38c5abf1d39213086b456c12d3cd2d0cd9375bf9f07710001f684142f2f41603ed45d8707c9b0f2680d0abea4c38ba64d86237d41f6b3c31c42357a626481a96
7
- data.tar.gz: a4234c0480d8b7c92c91cecf21aeaa5feabb08f1abc1c45f1c3c311c20b3431dbeb9b8a42ae69aa6de0c552a7becc738eccc60dd18b55825d1ee82228fe1ceb5
6
+ metadata.gz: 4c2eaf481b20f662ecac532f950c866ca7fc11d966e4a8b067ad67faca035e08d305923c6ad3a5c85025f3da7d3afc247b91461d4cbb2590cc126f26f28034b2
7
+ data.tar.gz: f639fd08740c4df9bcece0443a4b802d9d8df01de17c5136abe4c9fdf4b1a5b6bb09e7c6f04c3c4bd9ddd6127df39ff5aa67e98de72d550f7cf4aefc81193028
@@ -17,7 +17,8 @@ options = {
17
17
  limit: 1000,
18
18
  fields: 'host',
19
19
  post: false,
20
- query: nil
20
+ query: nil,
21
+ format: 'csv'
21
22
  }
22
23
 
23
24
  ARGV.options do |opts|
@@ -52,6 +53,10 @@ ARGV.options do |opts|
52
53
 
53
54
  opts.on(nil, '--size_per_page=SIZE', Integer, "API fetch size per page, default to #{options[:size_per_page]}") do |val|
54
55
  options[:size_per_page] = val.to_i
56
+ end
57
+
58
+ opts.on('-o', '--output-format=FORMAT', String, "Format of output, default to #{options[:format]}, can be csv or json") do |val|
59
+ options[:format] = val
55
60
  end
56
61
 
57
62
  opts.on('-d', '--fields=FIELDS', String, "Fields to return, split with ',', default to #{options[:fields]}") do |val|
@@ -110,6 +115,21 @@ unless options[:apikey]
110
115
  exit -1
111
116
  end
112
117
 
118
+ def log_record(options, r)
119
+ case options[:format]
120
+ when 'json'
121
+ if r.kind_of?(Array)
122
+ puts Hash[options[:fields].split(',').zip r].to_json
123
+ elsif r.kind_of?(Hash)
124
+ puts r.to_json
125
+ else
126
+ puts %Q|{"id":"#{r}"}|
127
+ end
128
+ when 'csv'
129
+ puts r.map{|v| v}.join("\t")
130
+ end
131
+ end
132
+
113
133
  case options[:mode]
114
134
  when :search
115
135
  if ARGV.empty? && !options[:query]
@@ -120,21 +140,25 @@ case options[:mode]
120
140
  query = options[:query] || ARGV.join(' ')
121
141
  puts "Query: '#{query}'"
122
142
  if options[:page] #search one page
123
- puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
143
+ Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
124
144
  .search(query, {
125
145
  page:options[:page],
126
146
  size:options[:limit],
127
147
  fields:options[:fields],
128
148
  post:options[:post]
129
- })
149
+ }).each{|r|
150
+ log_record(options, r)
151
+ }
130
152
  else
131
- puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
153
+ Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
132
154
  .search_all(query, {
133
155
  size:options[:limit],
134
156
  page_size:options[:size_per_page],
135
157
  fields:options[:fields],
136
158
  post:options[:post]
137
- })
159
+ }).each{|r|
160
+ log_record(options, r)
161
+ }
138
162
  end
139
163
 
140
164
  when :import_service
@@ -189,7 +213,7 @@ case options[:mode]
189
213
  ip_hash.delete(k) if v.size==0
190
214
  }
191
215
  semaphore.acquire
192
- puts ip_hash.to_json
216
+ log_record(options, ip_hash)
193
217
  semaphore.release
194
218
  end
195
219
  end
@@ -1,3 +1,6 @@
1
+ # 0.3.12
2
+ # fofacli add -o --output-format option, support csv(defualt) and json
3
+ #
1
4
  # 0.3.10
2
5
  # add query_ip_list mode
3
6
  #
@@ -13,5 +16,5 @@
13
16
  # 0.3.6
14
17
  # add fields
15
18
  module Fofa
16
- VERSION = "0.3.11"
19
+ VERSION = "0.3.12"
17
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - fofa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-03 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.5.1
125
+ rubygems_version: 2.6.3
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: A Ruby library to interact with the FOFA API. https://fofa.so