本文整理汇总了Python中SimpleHTTPServer.SimpleHTTPRequestHandler方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleHTTPServer.SimpleHTTPRequestHandler方法的具体用法?Python SimpleHTTPServer.SimpleHTTPRequestHandler怎么用?Python SimpleHTTPServer.SimpleHTTPRequestHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleHTTPServer
的用法示例。
在下文中一共展示了SimpleHTTPServer.SimpleHTTPRequestHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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)
示例2: serve
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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()
示例3: call
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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.")
示例4: __init__
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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))
示例5: do_POST
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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))
示例6: do_POST
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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)
示例7: test
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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()
示例8: __init__
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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())
示例9: webserver_port
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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
示例10: main
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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 #
##############
示例11: getRequester
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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
示例12: cookieRequester
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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
示例13: send_head
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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)
示例14: translate_path
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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
示例15: run
# 需要导入模块: import SimpleHTTPServer [as 别名]
# 或者: from SimpleHTTPServer import SimpleHTTPRequestHandler [as 别名]
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)