Report is now in .json format

This commit is contained in:
isterix 2020-07-21 00:00:09 +02:00
parent 1f0d8c3032
commit c509637865
4 changed files with 34 additions and 27 deletions

View file

@ -1,21 +1,23 @@
require 'net/http'
require 'json'
def main_loop
json_object = []
TIMES.times do
url = url_generator(DOMAINS, MODE)
puts(url) if LOG
begin
response = Net::HTTP.get_response(URI(url))
puts("#{url} exists!")
File.open("RB_report.txt", 'a+') {|f| f.write("\n#{url} | STATUS_CODE: #{response.code} | DETAILS: #{response.message}")}
json_object << Hash["website_url" => url, "response_type" => "SUCCESS", "response_code" => response.code, "response_details" => response.message]
rescue Exception => e # Unlike JS/PY, the number of existing websites that raise exceptions is small
if e.class != SocketError
puts("#{url} exists!")
File.open("RB_report.txt", 'a+') {|f| f.write("\n#{url} | ERROR_CODE: #{e.class.to_s} | DETAILS: #{e.to_s}")}
json_object << Hash["website_url" => url, "response_type" => "ERROR", "response_code" => e.class.to_s, "response_details" => e.to_s]
end
end
end
File.open("RB_report.txt", 'a+') {|f| f.write("\n---\n")}
File.open(REPORT_FILE, 'a+') {|f| f << json_object.to_json} if json_object.any?
puts("Finished at #{Time.new.hour}h#{Time.new.min}m\n")
end
@ -27,13 +29,15 @@ def url_generator(domains, mode)
end
TIMES = ARGV.include?('-t') ? ARGV[ARGV.index("-t") + 1].to_i : 3000
DOMAINS = ARGV.include?('-d') ? ARGV[ARGV.index("-d") + 1].split(",") : ['.com', '.net', '.edu', '.gov', '.cn', '.org']
DOMAINS = ARGV.include?('-d') ? ARGV[ARGV.index("-d") + 1].split(",") : ['.co', '.com', '.net', '.edu', '.gov', '.cn', '.org', '.cc']
MODE = ARGV.include?('-m') ? ARGV[ARGV.index("-m") + 1].split(",") : ['http']
LOG = ARGV.index("-l").class == Integer
REPORT_FILE = "RB_report_#{Time.new.day}#{Time.new.hour}#{Time.new.min}.json"
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")
File.open("RB_report.txt", 'a+') {|f| f.write("---")}
File.open(REPORT_FILE, 'a+')
main_loop