Guest User

Untitled

a guest
Oct 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. require 'shodanz'
  2. require 'command_lion'
  3. require 'yaml'
  4. require 'pry'
  5.  
  6. module Top10
  7. @rest_api = Shodanz.api.rest.new
  8. def self.check(product)
  9. begin
  10. @rest_api.host_count(product: product, facets: { country: 10 })["facets"]["country"].collect { |x| x.values }.to_h.invert
  11. rescue
  12. puts "Unable to succesffully check the Shodan API."
  13. exit 1
  14. end
  15. end
  16. end
  17.  
  18. CommandLion::App.run do
  19. name "Top 10 Countires Running a Product Using Shodan"
  20.  
  21. command :product do
  22. description "Search for this given product."
  23. type :string
  24. flag "--product"
  25.  
  26. # Check is Shodan Enviroemnt Variable Set
  27. before do
  28. unless ENV['SHODAN_API_KEY']
  29. puts "Need to set the 'SHODAN_API_KEY' enviroment variable before using this app!"
  30. exit 1 # [ ╯´・ω・]╯︵┸━┸)
  31. end
  32. if argument.empty?
  33. puts "What kind of nonsense is this?! You need to provide some argument..."
  34. exit 1 # [ ╯ ゚▽゚]╯︵┻━┻)
  35. end
  36. end
  37.  
  38. # Do stuff.
  39. action do
  40. result = Top10.check(argument)
  41. if options[:json].given?
  42. puts JSON.pretty_generate(result)
  43. elsif options[:yaml].given?
  44. puts result.to_yaml
  45. else
  46. result.each do |country, count|
  47. puts "#{country}\t#{count}"
  48. end
  49. end
  50. end
  51.  
  52. option :json do
  53. description "Use JSON as the format to output to STDOUT."
  54. flag "--json"
  55. end
  56.  
  57. option :yaml do
  58. description "Use YAML as the format to output to STDOUT."
  59. flag "--yaml"
  60. end
  61. end
  62. end
Add Comment
Please, Sign In to add comment