Web Server Type Determination Ruby Script

Posted by Ben Reubenstein Sat, 05 Apr 2008 13:18:00 GMT

After seeing the Python version, then the shell script version, I decided to write the Ruby version. You could use the class anywhere, but this example is a nice command line script you can call.

#!/usr/bin/env ruby

require 'net/http'

class WebServerInfo
  def self.server_type(host)
    http = Net::HTTP.new(host, 80)
    resp, data = http.get('/', nil)
    resp['server']
  end
end

if ARGV[0].nil?
  puts "usage: which_webserver DOMAIN || IP"
else
  puts WebServerInfo.server_type(ARGV[0])
end

Cheers to Corey Goldberg and Brock

Comments

Leave a comment

Comments