head.py
30分プログラム、その38。とっても不調。
HEADリクエストをいろんなサーバに送って遊ぼう。
$ python head.py microsoft.com 301 Moved Permanently Connection: close Date: Sat, 26 May 2007 13:41:12 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Location: http://www.microsoft.com/index.html Content-Length: 31 Content-Type: text/html Set-Cookie: ASPSESSIONIDAADDCDBA=FPOPOLPAFNANDMAGDABDGLFC; path=/ Cache-control: private
おお、ちゃんとIISを使ってる。
$ python head.py apple.com 302 Found Date: Sat, 26 May 2007 13:44:15 GMT Server: Apache/1.3.29 (Darwin) mod_perl/1.26 Location: http://www.apple.com/index.html Connection: close Content-Type: text/html; charset=iso-8859-1
import httplib import sys host = sys.argv[1] if len(sys.argv) > 2: port = sys.argv[2] else: port = 80 http = httplib.HTTPConnection(host,port) http.request('HEAD','/index.html') res = http.getresponse() print res.status,res.reason,"\n",res.msg http.close
- えらい簡単なやつでごめんなさい