Skip to content

Instantly share code, notes, and snippets.

@rumblestrut
Last active December 21, 2015 04:38
Show Gist options
  • Select an option

  • Save rumblestrut/6250713 to your computer and use it in GitHub Desktop.

Select an option

Save rumblestrut/6250713 to your computer and use it in GitHub Desktop.
Ruby script that tests if domains are up and resolving correctly.
require 'net/http'
pages = %w( www.ericjgruber.com
www.lawrencecoders.com
www.americanacollectors.com
www.witchesbecryin.com
)
threads = []
for page in pages
threads << Thread.new(page) { |myPage|
h = Net::HTTP.new(myPage, 80)
puts "Fetching: #{myPage}"
resp, data = h.get('/', nil)
puts "Got #{myPage}: #{resp.message}"
}
end
threads.each { |aThread| aThread.join }
@ruralocity

Copy link
Copy Markdown

Something like this?

require 'net/http'

pages = %w(
  www.ericjgruber.com
  www.lawrencecoders.com
  www.americanacollectors.com
  www.bitchesbecryin.com
)

threads = []

pages.each do |page|
  threads << Thread.new(page) do
    puts "Fetching #{page}"
    begin
      Net::HTTP.get_response(page, '/')
      puts "Successfully connected to #{page}"
    rescue SocketError
      puts "Unable to connect to #{page}"
    end
  end
end

threads.each { |thread| thread.join }

@rumblestrut

Copy link
Copy Markdown
Author

That works great, thanks!

Hey, where did my for loop go? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment