#! /usr/bin/env ruby

# This code is in the public domain
# Written by Robbert Haarman

require 'socket'

host = ARGV[0]

if host.index ?:
	hostname, port = host.split ':'
	port = port.to_i
else
	hostname = host
	port = 80
end

conn = TCPSocket.new hostname, port
conn.print "OPTIONS * HTTP/1.1\015\012Host: #{host}\015\012" +
	"Connection: close\015\012\015\012"

lines = conn.readlines
conn.close

lines.each do |line|
	print line.sub(/$/, '') if line =~ /^Server:/i
end
