shodanz 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shodanz/apis/exploits.rb +4 -4
- data/lib/shodanz/apis/rest.rb +1 -1
- data/lib/shodanz/apis/streaming.rb +1 -1
- data/lib/shodanz/apis/utils.rb +26 -23
- data/lib/shodanz/errors.rb +1 -1
- data/lib/shodanz/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4b13cd6886a40478480be6963df243daff8a70bc89386aaf837589a2d8ad301
|
4
|
+
data.tar.gz: 90f764801640b90765c5e2bbf84cc7be70f0dbfbf788f60315bebf3a24f3e8ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2da8666780fe6fd7560155c868a821c0ea353ac5515f7e794429a07b5b600729ee117fbb6d269d3316b1c502afd9a914b656d7cfd0ca2cf8a5a1b410cab1ed4
|
7
|
+
data.tar.gz: 4f44aac093e59b2f38ac942b7c6548abe25189180109f91a78e81b2f0ebbda235edf147625468252632f49cc806c0ad584f517074d6771716485e9d84be306b3
|
@@ -19,13 +19,13 @@ module Shodanz
|
|
19
19
|
attr_accessor :key
|
20
20
|
|
21
21
|
# The path to the REST API endpoint.
|
22
|
-
URL = 'https://exploits.shodan.io/
|
22
|
+
URL = 'https://exploits.shodan.io/'
|
23
23
|
|
24
24
|
# @param key [String] SHODAN API key, defaulted to
|
25
25
|
# the *SHODAN_API_KEY* enviroment variable.
|
26
26
|
def initialize(key: ENV['SHODAN_API_KEY'])
|
27
27
|
@url = URL
|
28
|
-
@
|
28
|
+
@client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(@url))
|
29
29
|
self.key = key
|
30
30
|
|
31
31
|
warn 'No key has been found or provided!' unless key?
|
@@ -50,7 +50,7 @@ module Shodanz
|
|
50
50
|
params = turn_into_query(**params)
|
51
51
|
facets = turn_into_facets(**facets)
|
52
52
|
params[:page] = page
|
53
|
-
get('search', **params.merge(**facets))
|
53
|
+
get('api/search', **params.merge(**facets))
|
54
54
|
end
|
55
55
|
|
56
56
|
# This method behaves identical to the "/search" method with
|
@@ -62,7 +62,7 @@ module Shodanz
|
|
62
62
|
params = turn_into_query(**params)
|
63
63
|
facets = turn_into_facets(**facets)
|
64
64
|
params[:page] = page
|
65
|
-
get('count', **params.merge(**facets))
|
65
|
+
get('api/count', **params.merge(**facets))
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
data/lib/shodanz/apis/rest.rb
CHANGED
@@ -22,7 +22,7 @@ module Shodanz
|
|
22
22
|
# @param key [String] SHODAN API key, defaulted to the *SHODAN_API_KEY* enviroment variable.
|
23
23
|
def initialize(key: ENV['SHODAN_API_KEY'])
|
24
24
|
@url = URL
|
25
|
-
@
|
25
|
+
@client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(@url))
|
26
26
|
self.key = key
|
27
27
|
|
28
28
|
warn 'No key has been found or provided!' unless key?
|
@@ -28,7 +28,7 @@ module Shodanz
|
|
28
28
|
# @param key [String] SHODAN API key, defaulted to the *SHODAN_API_KEY* enviroment variable.
|
29
29
|
def initialize(key: ENV['SHODAN_API_KEY'])
|
30
30
|
@url = URL
|
31
|
-
@
|
31
|
+
@client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(@url))
|
32
32
|
self.key = key
|
33
33
|
|
34
34
|
warn 'No key has been found or provided!' unless key?
|
data/lib/shodanz/apis/utils.rb
CHANGED
@@ -78,11 +78,11 @@ module Shodanz
|
|
78
78
|
return json
|
79
79
|
end
|
80
80
|
|
81
|
-
def getter(path,
|
81
|
+
def getter(path, **params)
|
82
82
|
# param keys should all be strings
|
83
83
|
params = params.transform_keys(&:to_s)
|
84
84
|
# build up url string based on special params
|
85
|
-
url = "
|
85
|
+
url = "/#{path}?key=#{@key}"
|
86
86
|
# special params
|
87
87
|
params.each do |param,value|
|
88
88
|
next if value.is_a?(String) && value.empty?
|
@@ -90,38 +90,41 @@ module Shodanz
|
|
90
90
|
url += "&#{param}=#{value}"
|
91
91
|
end
|
92
92
|
|
93
|
-
resp = @
|
93
|
+
resp = @client.get(url)
|
94
94
|
|
95
|
-
|
96
|
-
|
95
|
+
if resp.success?
|
96
|
+
# parse all lines in the response body as JSON
|
97
|
+
json = JSON.parse(resp.body.join)
|
97
98
|
|
98
|
-
|
99
|
+
handle_any_json_errors(json)
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
return json
|
102
|
+
else
|
103
|
+
raise "Got response status #{resp.status}"
|
104
|
+
end
|
103
105
|
ensure
|
106
|
+
@client.pool.close
|
104
107
|
resp&.close
|
105
|
-
@internet = Async::HTTP::Internet.new if one_shot
|
106
108
|
end
|
107
109
|
|
108
110
|
def poster(path, one_shot=false, **params)
|
109
111
|
# param keys should all be strings
|
110
112
|
params = params.transform_keys(&:to_s)
|
111
113
|
# make POST request to server
|
112
|
-
resp = @
|
114
|
+
resp = @client.post("/#{path}?key=#{@key}", nil, JSON.dump(params))
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
+
if resp.success?
|
117
|
+
json = JSON.parse(resp.body.join)
|
116
118
|
|
117
|
-
|
119
|
+
handle_any_json_errors(json)
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
-
|
121
|
+
return json
|
122
|
+
else
|
123
|
+
raise "Got response status #{resp.status}"
|
124
|
+
end
|
122
125
|
ensure
|
126
|
+
@client.pool.close
|
123
127
|
resp&.close
|
124
|
-
@internet = Async::HTTP::Internet.new if one_shot
|
125
128
|
end
|
126
129
|
|
127
130
|
def slurper(path, **params)
|
@@ -132,7 +135,7 @@ module Shodanz
|
|
132
135
|
counter = 0
|
133
136
|
end
|
134
137
|
# make GET request to server
|
135
|
-
resp = @
|
138
|
+
resp = @client.get("/#{path}?key=#{@key}", params)
|
136
139
|
# read body line-by-line
|
137
140
|
until resp.body.nil? || resp.body.empty?
|
138
141
|
resp.body.read.each_line do |line|
|
@@ -151,25 +154,25 @@ module Shodanz
|
|
151
154
|
|
152
155
|
def async_get(path, **params)
|
153
156
|
Async::Task.current.async do
|
154
|
-
getter(path,
|
157
|
+
getter(path, **params)
|
155
158
|
end
|
156
159
|
end
|
157
160
|
|
158
161
|
def sync_get(path, **params)
|
159
162
|
Async do
|
160
|
-
getter(path,
|
163
|
+
getter(path, **params)
|
161
164
|
end.wait
|
162
165
|
end
|
163
166
|
|
164
167
|
def async_post(path, **params)
|
165
168
|
Async::Task.current.async do
|
166
|
-
poster(path,
|
169
|
+
poster(path, **params)
|
167
170
|
end
|
168
171
|
end
|
169
172
|
|
170
173
|
def sync_post(path, **params)
|
171
174
|
Async do
|
172
|
-
poster(path,
|
175
|
+
poster(path, **params)
|
173
176
|
end.wait
|
174
177
|
end
|
175
178
|
|
data/lib/shodanz/errors.rb
CHANGED
@@ -15,7 +15,7 @@ module Shodanz
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class NoAPIKey < StandardError
|
18
|
-
def initialize(msg = 'No API key has been found or provided! ( setup your SHODAN_API_KEY environment
|
18
|
+
def initialize(msg = 'No API key has been found or provided! ( setup your SHODAN_API_KEY environment variable )')
|
19
19
|
super
|
20
20
|
end
|
21
21
|
end
|
data/lib/shodanz/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shodanz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kent 'picatz' Gruber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.0.6
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: A modern, async Ruby gem for Shodan, the world's first search engine for
|