Skip to content

Instantly share code, notes, and snippets.

@edmore
Created February 12, 2013 18:18
Show Gist options
  • Save edmore/4771995 to your computer and use it in GitHub Desktop.
Save edmore/4771995 to your computer and use it in GitHub Desktop.
Check if site is down from terminal (via proxy)
#! /usr/bin/env ruby
##########################################################
# Description - Check whether site is up or down via the
# command line.
# Added feature - proxy access
# Author - www.edmoremoyo.com
##########################################################
require "net/http"
require "uri"
require 'ostruct'
uri = URI.parse("http://www.isup.me/#{ARGV[0]}")
proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new
response = Net::HTTP::Proxy(proxy.host, proxy.port).get_response(uri)
if (response.code == '200')
data = Net::HTTP::Proxy(proxy.host, proxy.port).get(uri)
is_match = /is up/.match(data)
if (is_match)
puts "#{ARGV[0]} is UP! Jus you."
else
puts "#{ARGV[0]} is DOWN dude! Ain't just you."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment