fofa 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51b78658d768160754f6f32ebd1eb38f9c9a1f90
4
- data.tar.gz: 3b9634e71a8b0d1911e3febef7956ab384ccf6a3
3
+ metadata.gz: 49f7d62fe77e1389d972aa534eeb8e820140edfd
4
+ data.tar.gz: 7ccb4489b6c43316f1340595203616eb21f96d05
5
5
  SHA512:
6
- metadata.gz: edc85325d980675819fb60ae281d4286eaf39576c787fb96a8fc5f43093a14a9c1f6c2a2caa788f60d9da45252f7f1653e972b552e0aa626cf78ebb83ac13dee
7
- data.tar.gz: 06e0b7ab86fcaa6bd7608d5039cc983baeda3bc7075bbc804deefe3fcf28400d20185ae23160b343a56b453d04be5f6cc6256ab0ac2705b57f0ef47acdf4a6a4
6
+ metadata.gz: e2efc067981fde4bbeec5b1dcda5ca7148ebab4716c85e4bb017f8a26d3551c719ace01ca85221e1c2bd9e58b1f359de8a434b255721e39772ab82c87f6c6ea3
7
+ data.tar.gz: e6730bcdf797391f4f6ffd1a4d36f0c8289d3b9167fafaf895183340980055545413251c2763d3fd8c1f77c362555dbe80a4c2bf9e47f3d4e31765eef4e0cde4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fofa (0.3.7)
4
+ fofa (0.3.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -15,7 +15,9 @@ options = {
15
15
  split_size: 100,
16
16
  size_per_page: 100,
17
17
  limit: 1000,
18
- fields: 'host'
18
+ fields: 'host',
19
+ post: false,
20
+ query: nil
19
21
  }
20
22
 
21
23
  ARGV.options do |opts|
@@ -48,28 +50,40 @@ ARGV.options do |opts|
48
50
  options[:limit] = val.to_i
49
51
  end
50
52
 
51
- opts.on('-s', '--limit=SIZE', Integer, "Limit size to fetch, default to #{options[:limit]}") do |val|
52
- options[:limit] = val.to_i
53
- end
54
-
55
53
  opts.on(nil, '--size_per_page=SIZE', Integer, "API fetch size per page, default to #{options[:size_per_page]}") do |val|
56
54
  options[:size_per_page] = val.to_i
57
55
  end
58
56
 
59
57
  opts.on('-d', '--fields=FIELDS', String, "Fields to return, split with ',', default to #{options[:fields]}") do |val|
60
58
  options[:fields] = val
59
+ end
60
+
61
+ opts.on('-q', '--query_file=FILE_PATH', String, "POST Query file when large search string") do |val|
62
+ raise "File not exist of #{val}" unless File.exists? val
63
+ options[:query] = File.read(val).strip
64
+ options[:post] = true
61
65
  end
62
66
 
63
67
  opts.separator "Common Options:"
68
+
69
+ opts.on( nil, "--post", "POST query mode." ) do
70
+ options[:post] = true
71
+ end
64
72
 
65
73
  opts.on( "-h", "--help", "Show this message." ) do
66
74
  puts opts
67
75
  exit
68
- end
76
+ end
69
77
 
70
78
  opts.on( "-v", "--verbose", "Verbose mode." ) do
71
79
  options[:verbose] = true
72
- end
80
+ end
81
+
82
+ opts.separator ""
83
+ opts.separator "For example:"
84
+ opts.separator "\t fofacli -e aaa@bbb.com -a xxx domain=\"baidu.com\""
85
+ opts.separator "\t fofacli -e aaa@bbb.com -a xxx -s 100 domain=\"baidu.com\""
86
+ opts.separator "\t fofacli -e aaa@bbb.com -a xxx --query_file /tmp/fofaquery"
73
87
 
74
88
  begin
75
89
  opts.parse!
@@ -97,26 +111,28 @@ end
97
111
 
98
112
  case options[:mode]
99
113
  when :search
100
- if ARGV.empty?
114
+ if ARGV.empty? && !options[:query]
101
115
  puts "Fofa query not specified.".red
102
116
  puts ARGV.options
103
117
  exit -1
104
118
  end
105
- query = ARGV.join(' ')
119
+ query = options[:query] || ARGV.join(' ')
106
120
  puts "Query: '#{query}'"
107
121
  if options[:page] #search one page
108
122
  puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
109
123
  .search(query, {
110
124
  page:options[:page],
111
125
  size:options[:limit],
112
- fields:options[:fields]
126
+ fields:options[:fields],
127
+ post:options[:post]
113
128
  })
114
129
  else
115
130
  puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
116
131
  .search_all(query, {
117
132
  size:options[:limit],
118
133
  page_size:options[:size_per_page],
119
- fields:options[:fields]
134
+ fields:options[:fields],
135
+ post:options[:post]
120
136
  })
121
137
  end
122
138
 
@@ -126,7 +142,7 @@ when :import_service
126
142
  puts ARGV.options
127
143
  exit -1
128
144
  end
129
- puts "Import server from '#{options[:file]}'"
145
+ puts "Import service from '#{options[:file]}'"
130
146
  puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]}).import_service(options[:file], {split_size:options[:split_size], fields:options[:fields]})
131
147
  end
132
148
 
@@ -27,14 +27,23 @@ module Fofa
27
27
  # options: (Hash) page(default 1, only fetch one page), size(defualt 100)
28
28
  def search(query, options={})
29
29
  options = {page:1, size:100, fields:'host'}.merge(options)
30
- url = "#{@api_server}/api/v1/search/all?key=#{@apikey}&email=#{@email}&q=#{URI.escape(query)}&page=#{options[:page]}&size=#{options[:size]}&fields=#{options[:fields]}"
31
- puts url if @options[:debug]
30
+
31
+ url = "#{@api_server}/api/v1/search/all?key=#{@apikey}&email=#{@email}&page=#{options[:page]}&size=#{options[:size]}&fields=#{options[:fields]}"
32
+ url += "&q=#{URI.escape(query)}" unless options[:post]
33
+ puts url if @options[:debug]
32
34
  uri = URI.parse(url)
33
35
  http = Net::HTTP.new(uri.host, uri.port)
34
36
  if uri.scheme == 'https'
35
37
  http.use_ssl = true
36
38
  end
37
- req = Net::HTTP::Get.new(uri.request_uri)
39
+
40
+ if options[:post]
41
+ req = Net::HTTP::Post.new(uri.request_uri)
42
+ req.body = query
43
+ else
44
+ req = Net::HTTP::Get.new(uri.request_uri)
45
+ end
46
+
38
47
  resp = http.request(req)
39
48
  JSON.parse(resp.body)
40
49
  rescue => e
@@ -74,6 +83,7 @@ module Fofa
74
83
 
75
84
  break if all_res.size >= res['size'].to_i
76
85
  else
86
+ raise res['errmsg'] if res['errmsg']
77
87
  break
78
88
  end
79
89
  end
@@ -1,3 +1,6 @@
1
+ # 0.3.9
2
+ # add post option to fix '414 Request-URI Too Large'
3
+ #
1
4
  # 0.3.8
2
5
  # fix N+1 API request to N
3
6
  #
@@ -7,5 +10,5 @@
7
10
  # 0.3.6
8
11
  # add fields
9
12
  module Fofa
10
- VERSION = "0.3.8"
13
+ VERSION = "0.3.9"
11
14
  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.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - fofa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-05 00:00:00.000000000 Z
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler