fofa 0.3.4 → 0.3.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7f386c0c8e54fc37083568c58fd957a8441af9d
4
- data.tar.gz: 5794ccb6b38f5a754cbcf5acac65ce81cb2a7add
3
+ metadata.gz: b606d3c74e7a72421fbed9e71bbfca25c6d6d04f
4
+ data.tar.gz: 43e5737e0f67c22e92521e7fd33f73b9d46328a0
5
5
  SHA512:
6
- metadata.gz: 61ade528ad3f6f617b82e97aa2338f9c5b53c6ef095651f075a983ea3a9ee5584bc08da1a3490b0b4c716e3f803fc433830b0c5b9ca14cc52c2874c2b0424878
7
- data.tar.gz: 58d8d8bbc89d8fafcc56353dfbe2f9313ce10770932f42e6c3e5fd857d912a8062b3135a6095e32ba21bfd046e1b7b2036aefba4e683895394ca9d61d4a0072f
6
+ metadata.gz: 2760f21dd6300a39d30e58688c08651390542ceac468fff5b0cebf500f316c761880fc944f143229ad6b8843067c6123afb3444f7d7cf3491505d7aefb17ab85
7
+ data.tar.gz: 0b8fccd0f3fdd6a47c67714cc366489cfd1330c04c5112021f25deb2b3f32f337192339e39da75a5d1ffab76775b87c9f2146b45a23480eee83ecd4f090325e0
@@ -0,0 +1 @@
1
+ # Created by .ignore support plugin (hsz.mobi)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fofa (0.3.3)
4
+ fofa (0.3.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -6,14 +6,15 @@ require "optparse"
6
6
  require "colorize"
7
7
 
8
8
  options = {
9
- email: nil,
10
- apikey: nil,
9
+ email: ENV['FOFA_EMAIL'],
10
+ apikey: ENV['FOFA_KEY'],
11
11
  page: 1,
12
12
  verbose: false,
13
13
  file: nil,
14
14
  mode: :search,
15
15
  split_size: 100,
16
- limit: 100
16
+ limit: 100,
17
+ fields: 'host'
17
18
  }
18
19
 
19
20
  ARGV.options do |opts|
@@ -23,32 +24,36 @@ ARGV.options do |opts|
23
24
  opts.separator "Specific Options:"
24
25
 
25
26
  opts.on('-e', '--email=EMAIL', String, 'Email of fofa user') do |val|
26
- options[:email] = val
27
- end
27
+ options[:email] = val
28
+ end
28
29
 
29
- opts.on('-a', '--apikey=APIKEY', String, 'APIKEY of fofa user') do |val|
30
- options[:apikey] = val
31
- end
30
+ opts.on('-a', '--apikey=APIKEY', String, 'APIKEY of fofa user') do |val|
31
+ options[:apikey] = val
32
+ end
32
33
 
33
- opts.on('-p', '--page=PAGE', Integer, 'Page of query result') do |val|
34
- options[:page] = val.to_i
35
- end
34
+ opts.on('-p', '--page=PAGE', Integer, 'Page of query result') do |val|
35
+ options[:page] = val.to_i
36
+ end
36
37
 
37
- opts.on('-m', '--mode=MODE', String, 'Mode, default to [search], -f should be specified when [import_service] ') do |val|
38
- options[:mode] = val.to_sym
39
- end
38
+ opts.on('-m', '--mode=MODE', String, 'Mode, default to [search], -m should be specified when [import_service] ') do |val|
39
+ options[:mode] = val.to_sym
40
+ end
40
41
 
41
- opts.on('-f', '--file=FILE', String, 'Used at [import_service] mode') do |val|
42
- options[:file] = val
43
- end
42
+ opts.on('-f', '--file=FILE', String, 'Used at [import_service] mode') do |val|
43
+ options[:file] = val
44
+ end
44
45
 
45
- opts.on('-s', '--limit=SIZE', Integer, "Limit size to fetch, default to #{options[:limit]}") do |val|
46
- options[:limit] = val.to_i
47
- end
46
+ opts.on('-s', '--limit=SIZE', Integer, "Limit size to fetch, default to #{options[:limit]}") do |val|
47
+ options[:limit] = val.to_i
48
+ end
49
+
50
+ opts.on('-l', '--split_size=SIZE', Integer, "Used at [import_service] mode, default to #{options[:split_size]}") do |val|
51
+ options[:split_size] = val.to_i
52
+ end
48
53
 
49
- opts.on('-s', '--split_size=SIZE', Integer, "Used at [import_service] mode, default to #{options[:split_size]}") do |val|
50
- options[:split_size] = val.to_i
51
- end
54
+ opts.on('-d', '--fields=FIELDS', String, "Fields to return, split with ',', default to #{options[:fields]}") do |val|
55
+ options[:fields] = val
56
+ end
52
57
 
53
58
  opts.separator "Common Options:"
54
59
 
@@ -65,8 +70,9 @@ ARGV.options do |opts|
65
70
  opts.parse!
66
71
  rescue OptionParser::InvalidOption => e
67
72
  puts e
68
- options.query += e.args
69
- rescue
73
+ options.query += e.args
74
+ rescue => e
75
+ puts e
70
76
  puts opts
71
77
  exit
72
78
  end
@@ -93,7 +99,7 @@ when :search
93
99
  end
94
100
  query = ARGV.join(' ')
95
101
  puts "Query: '#{query}'"
96
- puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]}).search(query, {page:options[:page], size:options[:limit]})
102
+ puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]}).search(query, {page:options[:page], size:options[:limit], fields:options[:fields]})
97
103
  when :import_service
98
104
  unless options[:file]
99
105
  puts "File not specified.".red
@@ -101,6 +107,6 @@ when :import_service
101
107
  exit -1
102
108
  end
103
109
  puts "Import server from '#{options[:file]}'"
104
- puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]}).import_service(options[:file], {split_size:options[:split_size]})
110
+ puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]}).import_service(options[:file], {split_size:options[:split_size], fields:options[:fields]})
105
111
  end
106
112
 
@@ -0,0 +1,3 @@
1
+ rm fofa-*.gem
2
+ gem build fofa.gemspec
3
+ gem push fofa-*.gem
@@ -8,22 +8,26 @@ module Fofa
8
8
  def initialize(email, apikey, options={})
9
9
  @options = {debug:false}.merge options
10
10
  @api_server = ENV['FOFA_API_SERVER'] || 'https://fofa.so'
11
- @email = email
12
- @apikey = apikey
11
+ @email = email || ENV['FOFA_EMAIL']
12
+ @apikey = apikey || ENV['FOFA_KEY']
13
13
  end
14
14
 
15
15
  # Search page results from fofa
16
16
  #
17
- # Example:
17
+ # Example 1:
18
18
  # >> Fofa::API.new(email,apikey).search("host==baidu.com")
19
- # => {size:1, results:['1.1.1.1:80']}
19
+ # => {size:1, results:['1.1.1.1']}
20
+ #
21
+ # Example 2:
22
+ # >> Fofa::API.new(email,apikey).search("host==baidu.com", fields:'host,title,ip')
23
+ # => {size:1, results:[['1.1.1.1:81', 'title', '1.1.1.1']]}
20
24
  #
21
25
  # Arguments:
22
26
  # query: (String) fofa query string
23
27
  # options: (Hash) page(default 1, only fetch one page), size(defualt 100)
24
28
  def search(query, options={})
25
- options = {page:1,size:100}.merge(options)
26
- url = "#{@api_server}/api/v1/search/all?key=#{@apikey}&email=#{@email}&q=#{URI.escape(query)}&page=#{options[:page]}&size=#{options[:size]}"
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]}"
27
31
  puts url if @options[:debug]
28
32
  uri = URI.parse(url)
29
33
  http = Net::HTTP.new(uri.host, uri.port)
@@ -1,3 +1,5 @@
1
+ # 0.3.5
2
+ # add fields
1
3
  module Fofa
2
- VERSION = "0.3.4"
4
+ VERSION = "0.3.5"
3
5
  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.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - fofa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - ".gitignore"
63
64
  - CODE_OF_CONDUCT.md
64
65
  - Gemfile
65
66
  - Gemfile.lock
@@ -69,6 +70,7 @@ files:
69
70
  - bin/console
70
71
  - bin/fofacli
71
72
  - bin/setup
73
+ - build.sh
72
74
  - fofa.gemspec
73
75
  - lib/fofa.rb
74
76
  - lib/fofa/version.rb
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  version: '0'
93
95
  requirements: []
94
96
  rubyforge_project:
95
- rubygems_version: 2.6.8
97
+ rubygems_version: 2.5.1
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: A Ruby library to interact with the FOFA API. https://fofa.so