Skip to content

An asynchronous future!

Compare
Choose a tag to compare
@picatz picatz released this 01 May 18:23
· 141 commits to master since this release

Version 2.0.0 brings asynchronous I/O support by utilizing async!

Async Example

The following example script streams banners from shodan, and checks the IP addresses found against the experimental honeypot detector:

require 'async'
require 'shodanz'

client = Shodanz.client.new

client.streaming_api.banners do |banner|
  if ip = banner['ip_str']
    Async do
      score = client.rest_api.honeypot_score(ip).wait
      puts "#{ip} has a #{score * 100}% chance of being a honeypot"
    rescue Shodanz::Errors::RateLimited
      sleep rand
      retry
    rescue # any other errors
      next
    end
  end
end