From ad41e0568a8993da115ca37b069394785f4ccd10 Mon Sep 17 00:00:00 2001 From: Alexandre ZANNI <16578570+noraj@users.noreply.github.com> Date: Sun, 24 Nov 2019 02:58:01 +0100 Subject: [PATCH] markdown code block + syntax highlight --- README.md | 58 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index fcd2bb8..0f9be33 100644 --- a/README.md +++ b/README.md @@ -16,41 +16,53 @@ Before you can use the API, you need to have an API key. Setup the Shodan wrapper object: - require 'shodan' - - api = Shodan::Shodan.new(MY_API_KEY) +~~~ruby +require 'shodan' + +api = Shodan::Shodan.new(MY_API_KEY) +~~~ Print a list of cisco-ios devices: - result = api.search("cisco-ios") - result['matches'].each{ |host| - puts host['ip_str'] - } +~~~ruby +result = api.search("cisco-ios") +result['matches'].each{ |host| + puts host['ip_str'] +} +~~~ Print the 2nd page of results for the cisco-ios query: - result = api.search("cisco-ios", :page => 2) - result['matches'].each{ |host| - puts host['ip_str'] - } +~~~ruby +result = api.search("cisco-ios", :page => 2) +result['matches'].each{ |host| + puts host['ip_str'] +} +~~~ Find out how many results there are for "apache" and also return the top 5 organizations for the results: - result = api.count("apache", :facets => 'org:5') - puts "Total number of results: #{result['total']}" - puts result['facets'] +~~~ruby +result = api.count("apache", :facets => 'org:5') +puts "Total number of results: #{result['total']}" +puts result['facets'] +~~~ Get all the information SHODAN has on the IP 217.140.75.46: - host = api.host('217.140.75.46') - puts host.to_s +~~~ruby +host = api.host('217.140.75.46') +puts host.to_s +~~~ To properly handle potential errors, you should wrap all requests in a try/except block: - begin - api.search("cisco-ios") - rescue Exception => e - puts "Error: #{e.to_s}" - else - puts "Unknown error" - end +~~~ruby +begin + api.search("cisco-ios") +rescue Exception => e + puts "Error: #{e.to_s}" +else + puts "Unknown error" +end +~~~