Class: Shodan::Page

Inherits:
Array
  • Object
show all
Defined in:
lib/shodan/page.rb

Instance Method Summary collapse

Constructor Details

#initialize(hosts = []) {|page| ... } ⇒ Page

Creates a new Page object.

Parameters:

  • hosts (Array) (defaults to: [])

    The initial hosts.

Yields:

  • (page)

    If a block is given, it will be passed the page.

Yield Parameters:

  • page (Page)

    The newly created Page object.



38
39
40
41
42
# File 'lib/shodan/page.rb', line 38

def initialize(hosts=[],&block)
  super(hosts)

  block.call(self) if block
end

Instance Method Details

#datesArray<Date>

The dates that the hosts were added.

Returns:

  • (Array<Date>)

    The dates.



223
224
225
# File 'lib/shodan/page.rb', line 223

def dates
  Enumerator.new(self,:each_date).to_a
end

#each_date {|date| ... } ⇒ self

Iterates over the dates that each host was added.

Yields:

  • (date)

    If a block is given, it will be passed the dates that each host was added.

Yield Parameters:

  • date (Date)

    A date that a host was added.

Returns:

  • (self)


211
212
213
214
215
# File 'lib/shodan/page.rb', line 211

def each_date(&block)
  each do |host|
    block.call(host.date) if block
  end
end

#each_hostname {|hostname| ... } ⇒ self

Iterates over the host names of every host in the page.

Yields:

  • (hostname)

    If a block is given, it will be passed the host names of every host.

Yield Parameters:

  • hostname (String)

    A host name.

Returns:

  • (self)


158
159
160
161
162
# File 'lib/shodan/page.rb', line 158

def each_hostname(&block)
  each do |host|
    block.call(host.hostname) if (block && host.hostname)
  end
end

#each_http_headers {|headers| ... } ⇒ self

Itereates over the HTTP headers of each host in the page.

Yields:

  • (headers)

    If a block is given, it will be passed the headers from each host in the page.

Yield Parameters:

  • headers (Hash)

    The headers from a host in the page.

Returns:

  • (self)


291
292
293
294
295
# File 'lib/shodan/page.rb', line 291

def each_http_headers(&block)
  each do |host|
    block.call(host.http_headers) if block
  end
end

#each_ip {|ip| ... } ⇒ self

Iterates over the IP addresses of every host in the page.

Yields:

  • (ip)

    If a block is given, it will be passed the IP addresses of every host.

Yield Parameters:

  • ip (String)

    An IP address of a host.

Returns:

  • (self)


106
107
108
109
110
# File 'lib/shodan/page.rb', line 106

def each_ip(&block)
  each do |host|
    block.call(host.ip) if block
  end
end

#each_response {|response| ... } ⇒ self

Iterates over the responses of each host in the page.

Yields:

  • (response)

    If a block is given, it will be passed the responses of each host.

Yield Parameters:

  • response (String)

    The initial response of a host.

Returns:

  • (self)


238
239
240
241
242
# File 'lib/shodan/page.rb', line 238

def each_response(&block)
  each do |host|
    block.call(host.response) if block
  end
end

#hostnamesArray<String>

The names of the hosts in the page.

Returns:

  • (Array<String>)

    The host names.



195
196
197
# File 'lib/shodan/page.rb', line 195

def hostnames
  Enumerator.new(self,:each_hostname).to_a
end

#hosts_with_ip(ip) {|host| ... } ⇒ Array<Host>

Selects the hosts with the matching IP address.

Parameters:

  • ip (Regexp, String)

    The IP address to search for.

Yields:

  • (host)

    If a block is also given, it will be passed every matching host.

Yield Parameters:

  • host (Host)

    A host with the matching IP address.

Returns:

  • (Array<Host>)

    The hosts with the matching IP address.



127
128
129
130
131
132
133
134
135
# File 'lib/shodan/page.rb', line 127

def hosts_with_ip(ip,&block)
  hosts_with do |host|
    if host.ip.match(ip)
      block.call(host) if block
      
      true
    end
  end
end

#hosts_with_name(name) {|host| ... } ⇒ Array<Host>

Selects the hosts with the matching host name.

Parameters:

  • hostname (Regexp, String)

    The host name to search for.

Yields:

  • (host)

    If a block is also given, it will be passed every matching host.

Yield Parameters:

  • host (Host)

    A host with the matching host name.

Returns:

  • (Array<Host>)

    The hosts with the matching host name.



179
180
181
182
183
184
185
186
187
# File 'lib/shodan/page.rb', line 179

def hosts_with_name(name,&block)
  hosts_with do |host|
    if (host.hostname && host.hostname.match(name))
      block.call(host) if block

      true
    end
  end
end

#http_headersArray<Hash>

The HTTP headers from the hosts in the page.

Returns:

  • (Array<Hash>)

    The HTTP headers.



303
304
305
# File 'lib/shodan/page.rb', line 303

def http_headers
  Enumerator.new(self,:each_http_headers).to_a
end

#ipsArray<String>

The IP addresses of the hosts in the page.

Returns:

  • (Array<String>)

    The IP addresses.



143
144
145
# File 'lib/shodan/page.rb', line 143

def ips
  Enumerator.new(self,:each_ip).to_a
end

#map {|host| ... } ⇒ Array

Maps the hosts within the page.

Examples:

page.map
# => #<Page: ...>
page.map { |host| host.ip }
# => [...]

Yields:

  • (host)

    The given block will be used to map each host in the page.

Yield Parameters:

  • host (Host)

    A host within the page.

Returns:

  • (Array)

    The resulting mapped Array.



64
65
66
67
68
69
70
71
# File 'lib/shodan/page.rb', line 64

def map(&block)
  return self unless block

  mapped = []

  each { |element| mapped << block.call(element) }
  return mapped
end

#responses(&block) ⇒ Array<String>

The responses of the hosts in the page.

Returns:

  • (Array<String>)

    The responses.



275
276
277
# File 'lib/shodan/page.rb', line 275

def responses(&block)
  Enumerator.new(self,:each_response).to_a
end

#responses_with(pattern) {|host| ... } ⇒ Array<Host>

Selects the hosts with the matching response.

Parameters:

  • pattern (Regexp, String)

    The response pattern to search for.

Yields:

  • (host)

    If a block is also given, it will be passed every matching host.

Yield Parameters:

  • host (Host)

    A host with the matching response.

Returns:

  • (Array<Host>)

    The hosts with the matching response.



259
260
261
262
263
264
265
266
267
# File 'lib/shodan/page.rb', line 259

def responses_with(pattern,&block)
  hosts_with do |host|
    if host.response.match(pattern)
      block.call(host) if block

      true
    end
  end
end

#select {|host| ... } ⇒ Page Also known as: hosts_with

Selects the hosts within the page.

Examples:

page.select { |host| host.headers['Server'] =~ /IIS/ }

Yields:

  • (host)

    The given block will be used to select hosts from the page.

Yield Parameters:

  • host (Host)

    A host in the page.

Returns:

  • (Page)

    A sub-set of the hosts within the page.



88
89
90
# File 'lib/shodan/page.rb', line 88

def select(&block)
  self.class.new(super(&block))
end