Created
April 1, 2013 07:28
-
-
Save izawa/5283653 to your computer and use it in GitHub Desktop.
basic authentication cheker over HTTPs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! env ruby | |
require 'net/https' | |
require 'optparse' | |
Server="www.example.com" | |
Port=443 | |
CAfile="/usr/local/share/ca-bundle.crt" | |
def usage | |
puts("Usage: checkauth.rb -i <datafile>") | |
exit | |
end | |
def getStatusCode (username, password, remote_content) | |
https = Net::HTTP.new(Server,Port) | |
https.use_ssl = true | |
https.ca_file = CAfile | |
https.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
https.verify_depth = 5 | |
https.start { | |
req = Net::HTTP::Get.new(remote_content) | |
req.basic_auth(username, password) | |
response = https.request(req) | |
response.code | |
} | |
end | |
opt = OptionParser.new | |
option=Hash.new | |
opt.on('-i VAL') {|v| option[:i] = v } | |
opt.parse!(ARGV) | |
usage unless option[:i] | |
IO.foreach(option[:i]){ |line| | |
next if line =~ /^\s*#/ | |
record = line.split | |
next if record.size != 3 | |
code = getStatusCode(record[0], record[1], record[2]).to_i | |
if code == 200 | |
print "#{record[0]} ... OK\n" | |
else | |
print "HTTP CODE = #{code}, user: #{record[0]} , pass: #{record[1]} for #{record[2]}\n" | |
end | |
} | |
__END__ | |
data file format: | |
username<space>password<space>URL for content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment