2020-07-15 19:28:36 +02:00
|
|
|
require 'net/http'
|
2020-07-21 00:00:09 +02:00
|
|
|
require 'json'
|
2020-07-15 19:28:36 +02:00
|
|
|
|
|
|
|
def main_loop
|
2020-07-21 00:00:09 +02:00
|
|
|
json_object = []
|
2020-07-15 19:28:36 +02:00
|
|
|
TIMES.times do
|
|
|
|
url = url_generator(DOMAINS, MODE)
|
|
|
|
puts(url) if LOG
|
|
|
|
begin
|
|
|
|
response = Net::HTTP.get_response(URI(url))
|
|
|
|
puts("#{url} exists!")
|
2020-07-21 00:00:09 +02:00
|
|
|
json_object << Hash["website_url" => url, "response_type" => "SUCCESS", "response_code" => response.code, "response_details" => response.message]
|
2020-07-15 19:28:36 +02:00
|
|
|
rescue Exception => e # Unlike JS/PY, the number of existing websites that raise exceptions is small
|
|
|
|
if e.class != SocketError
|
|
|
|
puts("#{url} exists!")
|
2020-07-21 00:00:09 +02:00
|
|
|
json_object << Hash["website_url" => url, "response_type" => "ERROR", "response_code" => e.class.to_s, "response_details" => e.to_s]
|
2020-07-15 19:28:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-21 00:00:09 +02:00
|
|
|
File.open(REPORT_FILE, 'a+') {|f| f << json_object.to_json} if json_object.any?
|
2020-07-15 19:28:36 +02:00
|
|
|
puts("Finished at #{Time.new.hour}h#{Time.new.min}m\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def url_generator(domains, mode)
|
|
|
|
result = mode[rand(0..mode.length - 1)] + '://'
|
|
|
|
url_length = rand(2..30)
|
|
|
|
result += rand(36 ** url_length).to_s(36)
|
|
|
|
result += domains[rand(0..domains.length - 1)]
|
|
|
|
end
|
|
|
|
|
|
|
|
TIMES = ARGV.include?('-t') ? ARGV[ARGV.index("-t") + 1].to_i : 3000
|
2020-07-21 00:00:09 +02:00
|
|
|
DOMAINS = ARGV.include?('-d') ? ARGV[ARGV.index("-d") + 1].split(",") : ['.co', '.com', '.net', '.edu', '.gov', '.cn', '.org', '.cc']
|
2020-07-15 19:28:36 +02:00
|
|
|
MODE = ARGV.include?('-m') ? ARGV[ARGV.index("-m") + 1].split(",") : ['http']
|
|
|
|
LOG = ARGV.index("-l").class == Integer
|
|
|
|
|
2020-07-21 00:00:09 +02:00
|
|
|
REPORT_FILE = "RB_report_#{Time.new.day}#{Time.new.hour}#{Time.new.min}.json"
|
|
|
|
|
2020-07-15 19:28:36 +02:00
|
|
|
puts("\nI am going to look for images through #{TIMES} random URLs with the following domains: #{DOMAINS}")
|
|
|
|
puts("These URLs will use the following protocols: #{MODE}")
|
|
|
|
puts("Started at #{Time.new.hour}h#{Time.new.min}m\n")
|
|
|
|
|
2020-07-21 00:00:09 +02:00
|
|
|
File.open(REPORT_FILE, 'a+')
|
2020-07-15 19:28:36 +02:00
|
|
|
main_loop
|