Class: Shodanz::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/shodanz/client.rb

Overview

General client container class for all three of the available API endpoints in a convenient place to use.

Author:

  • Kent ‘picat’ Gruber

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: ENV['SHODAN_API_KEY']) ⇒ Client

Create a new client to connect to any of the APIs.

Optionally provide your Shodan API key, or the environment variable SHODAN_API_KEY will be used.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shodanz/client.rb', line 21

def initialize(key: ENV['SHODAN_API_KEY'])
  raise Shodanz::Errors::NoAPIKey if key.nil?

  # pass the given API key to each of the underlying clients
  #
  # Note: you can optionally change these API keys later, if you
  # had multiple for whatever reason. ;)
  #
  @rest_api      = Shodanz.api.rest.new(key: key)
  @streaming_api = Shodanz.api.streaming.new(key: key)
  @exploits_api  = Shodanz.api.exploits.new(key: key)
end

Instance Attribute Details

#exploits_apiShodanz::API::Exploits (readonly)



15
16
17
# File 'lib/shodanz/client.rb', line 15

def exploits_api
  @exploits_api
end

#rest_apiShodanz::API::REST (readonly)

Returns:



11
12
13
# File 'lib/shodanz/client.rb', line 11

def rest_api
  @rest_api
end

#streaming_apiShodanz::API::Streaming (readonly)



13
14
15
# File 'lib/shodanz/client.rb', line 13

def streaming_api
  @streaming_api
end

Instance Method Details

#community_queries(**params) ⇒ Object



70
71
72
# File 'lib/shodanz/client.rb', line 70

def community_queries(**params)
  rest_api.community_queries(params)
end

#crawl_for(**params) ⇒ Object



62
63
64
# File 'lib/shodanz/client.rb', line 62

def crawl_for(**params)
  rest_api.scan(params)
end

#exploit_count(query = '', page: 1, **params) ⇒ Object



114
115
116
# File 'lib/shodanz/client.rb', line 114

def exploit_count(query = '', page: 1, **params)
  exploits_api.count(query, page: page, **params)
end

#exploit_search(query = '', page: 1, **params) ⇒ Object



110
111
112
# File 'lib/shodanz/client.rb', line 110

def exploit_search(query = '', page: 1, **params)
  exploits_api.search(query, page: page, **params)
end

#honeypot_score(ip) ⇒ Object



102
103
104
# File 'lib/shodanz/client.rb', line 102

def honeypot_score(ip)
  rest_api.honeypot_score(ip)
end

#host(ip, **params) ⇒ Object



34
35
36
# File 'lib/shodanz/client.rb', line 34

def host(ip, **params)
  rest_api.host(ip, **params)
end

#host_count(query = '', facets: {}, **params) ⇒ Object



38
39
40
# File 'lib/shodanz/client.rb', line 38

def host_count(query = '', facets: {}, **params)
  rest_api.host_count(query, facets: facets, **params)
end

#host_search(query = '', facets: {}, page: 1, minify: true, **params) ⇒ Object



42
43
44
# File 'lib/shodanz/client.rb', line 42

def host_search(query = '', facets: {}, page: 1, minify: true, **params)
  rest_api.host_search(query, facets: facets, page: page, minify: minify, **params)
end

#host_search_tokens(query = '', **params) ⇒ Object



46
47
48
# File 'lib/shodanz/client.rb', line 46

def host_search_tokens(query = '', **params)
  rest_api.host_search(query, params)
end

#http_headersObject



94
95
96
# File 'lib/shodanz/client.rb', line 94

def http_headers
  rest_api.http_headers
end

#infoObject



106
107
108
# File 'lib/shodanz/client.rb', line 106

def info
  rest_api.info
end

#my_ipObject



98
99
100
# File 'lib/shodanz/client.rb', line 98

def my_ip
  rest_api.my_ip
end


78
79
80
# File 'lib/shodanz/client.rb', line 78

def popular_query_tags(size = 10)
  rest_api.popular_query_tags(size)
end

#portsObject



50
51
52
# File 'lib/shodanz/client.rb', line 50

def ports
  rest_api.ports
end

#profileObject



82
83
84
# File 'lib/shodanz/client.rb', line 82

def profile
  rest_api.profile
end

#protocolsObject



54
55
56
# File 'lib/shodanz/client.rb', line 54

def protocols
  rest_api.protocols
end

#resolve(*hostnames) ⇒ Object



86
87
88
# File 'lib/shodanz/client.rb', line 86

def resolve(*hostnames)
  rest_api.resolve(hostnames)
end

#reverse_lookup(*ips) ⇒ Object



90
91
92
# File 'lib/shodanz/client.rb', line 90

def reverse_lookup(*ips)
  rest_api.reverse_lookup(ips)
end

#scan(*ips) ⇒ Object



58
59
60
# File 'lib/shodanz/client.rb', line 58

def scan(*ips)
  rest_api.scan(ips)
end

#scan_status(id) ⇒ Object



66
67
68
# File 'lib/shodanz/client.rb', line 66

def scan_status(id)
  rest_api.scan_status(id)
end

#search_for_community_query(query, **params) ⇒ Object



74
75
76
# File 'lib/shodanz/client.rb', line 74

def search_for_community_query(query, **params)
  rest_api.search_for_community_query(query, params)
end