Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'net/http'
- require 'uri'
- # ensure that we're getting a first argument and that it's a valid URI
- abort("You must specify a hostname as the first argument.") if ARGV.first.nil?
- abort("Invalid URI") unless uri = URI.parse(ARGV.first)
- # create our request object
- req = Net::HTTP::Head.new(uri.request_uri)
- http = Net::HTTP.new(uri.host, uri.port)
- req.add_field("Host", uri.host)
- # add the custom range headers to our request object
- # we're adding 100 different ranges with offsets between 1 and 100.
- 1000.times do
- req.add_field("Range", "5-#{Random.rand(0..1300)}")
- end
- # get the response by making the request
- # TODO: make this block easier to understand
- res = http.request(req)
- # print out our request and response
- puts "Request: #{res.inspect}"
- req.each do |key,value|
- puts "#{key}: #{value}"
- end
- puts "\n"
- puts "Response: #{res.inspect}"
- res.each do |key,value|
- puts "#{key}: #{value}"
- end
Add Comment
Please, Sign In to add comment