This script came about from me playing with similar examples in two books that I own: Black Hat Python (by Justin Seitz) and Violent Python (by TJ O'Connor). It's sort of a combination of ideas from both, with some other tweaks from looking about the web and trying things myself.
import socket
host = "google.com" #any site name or IP address
port = 80
addr = (host, port)
s = socket.socket()
s.connect (addr)
s.send ("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n")
print s.recv (1024)
1024 should be enough to grab the banner, which is where you'll get useful stuff like server type, etc. You can increase it to 2048 or 4096, or just repeat the last line to get more from the connection, which is still open. Ideally, when you are finished, you should really do a s.close() rather than let the connection time out.
Note that the line s = socket.socket() is relying on the default settings for this, which is:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
This is the default for an IPv4 TCP connection. As sites increasingly move to IPv6, this default may not give the results you expect.