Skip to content

Instantly share code, notes, and snippets.

@thomasp11
Created April 8, 2016 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasp11/a98e892ea3e97d2fc3686e60cc4ebbe2 to your computer and use it in GitHub Desktop.
Save thomasp11/a98e892ea3e97d2fc3686e60cc4ebbe2 to your computer and use it in GitHub Desktop.
Prints URLs to each CloudShark capture found
#!/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