esxi4で動く簡易ウェブサーバ(セキュリティ無視) #!/bin/python import BaseHTTPServer,SocketServer,sys,os,urlparse class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): scm,netloc,path,params,query,fragment=urlparse.urlparse(self.path,'http') if os.path.isdir(path): if not path.endswith('/'):path+='/' html='<html><head><title>Index of '+path+'</title></head><body><ul>' html+=''.join(['<li><a href="%s%s">%s</a></li>'%(path,d,d) for d in os.listdir(path)]) html+='</ul></body></html>' self.send_response(200) self.send_header('Content-Type','text/html') self.send_header('Content-Length',len(html)) self.end_headers() self.wfile.write(html) elif os.path.isfile(path): self.send_response(200) self.send_header('Content-Type','text/plain') self.send_header('Content-Length',os.stat(path).st_size) self.end_headers() self.wfile.write(file(path).read()) else: self.send_error(404) class ThreadingHTTPServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):pass if __name__=='__main__': if len(sys.argv)<2:sys.argv.append('7777') #os.chroot('/etc') BaseHTTPServer.test(MyHandler,ThreadingHTTPServer,'HTTP/1.1')