I wrote the following code:
require 'net/http'
require 'uri'
require 'IPAddr'
require 'timeout'
require 'Resolv'
require 'open-uri'
#puts "Origin IP:\n\n"
#originip = gets()
(IPAddr.new("209.85.175.120")..IPAddr.new("209.85.175.150")).each do |address|
uri = URI("http://#{address.to_s}")
puts "#{uri}"
http = Net::HTTP.new(uri.host, uri.port)
puts "#{http}"
Net::HTTP.start(uri.host, uri.port) do |http|
request = Net::HTTP::Get.new uri.request_uri
response = http.request request
if response.code == "301" || response.code == "400" then
end
#request.initialize_http_header({"Origin" => "#{originip}"})
end
Is it possible to go to line uri = URI("http://#{address.to_s}")
in my if
condition
if response.code == "301" || response.code == "400" then
# condition
end
in the above code becomes true? How can I go to the next IP address and skip the current one if my condition becomes true?
Is it possible to do something like a label and goto
statement in Ruby?
next if response.code == "301" || response.code == "400"