Class: Mihari::Clients::Shodan

Inherits:
Base
  • Object
show all
Defined in:
lib/mihari/clients/shodan.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#base_url, #headers

Instance Method Summary collapse

Constructor Details

#initialize(base_url = "https://api.shodan.io", api_key:, headers: {}) ⇒ Shodan

Returns a new instance of Shodan.

Parameters:

  • base_url (String) (defaults to: "https://api.shodan.io")
  • api_key (String, nil)
  • headers (Hash) (defaults to: {})

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
# File 'lib/mihari/clients/shodan.rb', line 14

def initialize(base_url = "https://api.shodan.io", api_key:, headers: {})
  raise(ArgumentError, "'api_key' argument is required") unless api_key

  super(base_url, headers: headers)

  @api_key = api_key
end

Instance Attribute Details

#api_keyString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/mihari/clients/shodan.rb', line 7

def api_key
  @api_key
end

Instance Method Details

#search(query, page: 1, minify: true) ⇒ Structs::Shodan::Result

Parameters:

  • query (String)
  • page (Integer) (defaults to: 1)
  • minify (Boolean) (defaults to: true)

Returns:



29
30
31
32
33
34
35
36
37
38
# File 'lib/mihari/clients/shodan.rb', line 29

def search(query, page: 1, minify: true)
  params = {
    query: query,
    page: page,
    minify: minify,
    key: api_key
  }
  res = get("/shodan/host/search", params: params)
  Structs::Shodan::Result.from_dynamic! JSON.parse(res.body.to_s)
end