首页 > 代码库 > http 请求头回显
http 请求头回显
代码速记:
#encoding: utf-8 #author: walker #date: 2017-07-24 #summary: 回显http头,可用于匿名度检测 import argparse from colored import fg, bg, attr from http.server import HTTPServer, BaseHTTPRequestHandler class EchoHTTPHandler(BaseHTTPRequestHandler): #将请求头包装成html,便于返回给http客户端 def text_to_html(self, req_head): html = ‘<html><head><title>Echo HTTP Header</title></head>‘ html += ‘<body><div>‘ html += ‘<font color="blue">%s - %s - %s</font><br/><br/>‘ % (self.client_address, self.request_version, self.path) for line in req_head.split(‘\n‘): line = line.strip() if line.startswith(‘Via:‘) or line.startswith(‘X-Forwarded-For:‘): line = ‘<font color="red">%s</font><br/>‘ % line else: line = ‘<font color="black">%s</font><br/>‘ % line html += line html += ‘</div></body></html>‘ return html #响应get请求,打印http头,并返回给http客户端 def do_GET(self): print(‘%s - %s - %s‘ % (self.client_address, self.request_version, self.path)) print(type(self.client_address)) print(‘### request headers ###‘) req_head = str(self.headers) for line in req_head.split(‘\n‘): line = line.strip() if line.startswith(‘Via:‘) or line.startswith(‘X-Forwarded-For:‘): line = ‘%s%s%s‘ % (fg(‘red‘), line, attr(‘reset‘)) print(line) self.send_response(200) self.end_headers() self.wfile.write(self.text_to_html(req_head).encode(‘utf8‘)) if __name__ == ‘__main__‘: parser = argparse.ArgumentParser(description=‘Echo HTTP server.‘) parser.add_argument(‘-a‘, ‘--address‘, help=‘default: 0.0.0.0‘) parser.add_argument(‘-p‘, ‘--port‘, help=‘default: 8080‘, type=int) args = parser.parse_args() server = HTTPServer((args.address or ‘0.0.0.0‘, args.port or 8080), EchoHTTPHandler) server.serve_forever()
相关阅读:
1、http.server — HTTP servers
2、colored
*** walker ***
本文出自 “walker的流水账” 博客,请务必保留此出处http://walkerqt.blog.51cto.com/1310630/1950505
http 请求头回显
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。