Skip to content

Instantly share code, notes, and snippets.

@bhuvangu
Created December 12, 2013 04:25
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 bhuvangu/7923170 to your computer and use it in GitHub Desktop.
Save bhuvangu/7923170 to your computer and use it in GitHub Desktop.
Gist to check ip responding with code 200
ips =["74.125.34.181",
"74.125.34.126",
"74.125.34.252",
"74.125.34.247",
"74.125.34.254"];
def get_page(ip)
uri = URI("http://#{ip}")
begin
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
if response.code == '200' then
puts "responding ip::#{ip}" ;
else
puts "#{ip} not responsding";
end
rescue
puts "#{ip} not responsding"
end
end
threads = [];
ips.each_with_index do |ip,i|
threads << Thread.new{ get_page(ip) }
# wait for 3 sec. so that we dont collapse under our own wt of threads.(applicable if ips list is too large)
if(i%20 == 0) then
puts "sleep::#{i}"
sleep(3);
end
end
threads.map {|t| t.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment