Advertisement
Guest User

Untitled

a guest
Feb 28th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.96 KB | None | 0 0
  1. require 'net/http'
  2. require 'net/http/digest_auth'
  3. require 'uri'
  4.  def server_info(s_number = 0)
  5.     output = false
  6.     digest_auth = Net::HTTP::DigestAuth.new
  7.     uri = URI.parse('http://localhost:9999/') #@servers[s_number.to_i - 1]
  8.     uri.user = 'admin'
  9.     uri.password = 'national0987'
  10.     h = Net::HTTP.new uri.host, uri.port
  11.     req = Net::HTTP::Get.new uri.request_uri
  12.     Timeout.timeout(5) do
  13.       begin
  14.           res = h.request req
  15.           # res is a 401 response with a WWW-Authenticate header
  16.           auth = digest_auth.auth_header uri, res['www-authenticate'], 'GET'
  17.           # create a new request with the Authorization header
  18.           req = Net::HTTP::Get.new uri.request_uri
  19.           req.add_field 'Authorization', auth
  20.           # re-issue request with Authorization
  21.           res = h.request req
  22.           output = res.body
  23.           output = false
  24.       rescue
  25.         output = false
  26.       end
  27.     end
  28.  end
  29.  server_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement