Created
April 8, 2016 17:16
-
-
Save thomasp11/a98e892ea3e97d2fc3686e60cc4ebbe2 to your computer and use it in GitHub Desktop.
Prints URLs to each CloudShark capture found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'date' | |
require 'time' | |
require 'json' | |
require 'open-uri' | |
require 'openssl' | |
############################################################################### | |
# | |
# Please fill in the following section with your settings: | |
# | |
################ VARIABLES TO SET ############################################# | |
api_token="<INSERT API TOKEN HERE" | |
server="https://www.cloudshark.org/" | |
https=true | |
verify_cert=true | |
captures_per_page=30 | |
verbose=false | |
################ END VARIABLES ################################################ | |
if verify_cert | |
verify_cert = OpenSSL::SSL::VERIFY_PEER | |
else | |
verify_cert = OpenSSL::SSL::VERIFY_NONE | |
end | |
params = "" | |
page = 1 | |
uri = "#{server}/api/v1/#{api_token}/search.json?#{params}&limit=#{captures_per_page}&page=#{page}" | |
if verbose | |
puts "Searching for files via API:" | |
puts uri | |
end | |
response = open(uri, {ssl_verify_mode: verify_cert}).read | |
res = JSON.parse(response) | |
while page <= res['total_pages'] do | |
uri = "#{server}/api/v1/#{api_token}/search.json?#{params}&page=#{page}" | |
response = open(uri, {ssl_verify_mode: verify_cert}).read | |
res = JSON.parse(response) | |
res['captures'].each do |cap| | |
# Here you could perform an operation on each capture found | |
# This example prints the URL for each capture file | |
puts "#{server}captures/#{cap['id']}" | |
end | |
page += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment