代码拉取完成,页面将自动刷新
# -- coding: utf-8 --
# Name: generate_pcap.py
# Where:
from flask import Blueprint, render_template, request, redirect, url_for, jsonify, send_from_directory
import os
from pcaps_create import creat_http_pcap, fix_content_length # 确保此路径正确
from http_requests import standard_get, ordinary_post, form_submission
from http_responses import http_response_200, http_response_302, http_response_404, http_response_502
# 创建一个Blueprint对象
generate_pcap = Blueprint('generate_pcap', __name__, template_folder='./')
@generate_pcap.route('/generate_pcap', methods=['GET', 'POST'])
def generate():
template_response = "" # 用于存放选择的模板响应内容
request_body = "" # 用于存放请求体的内容
if request.method == 'POST':
# 处理HTTP请求模板的选择
request_template_name = request.form.get('request_template', '')
if request_template_name == "标准GET":
request_body = standard_get()
elif request_template_name == "普通POST":
request_body = ordinary_post()
elif request_template_name == "FORM提交":
request_body = form_submission()
# 处理HTTP响应模板的选择
template_name = request.form.get('template', '')
if template_name == "模板200":
template_response = http_response_200()
elif template_name == "模板302":
template_response = http_response_302()
elif template_name == "模板404":
template_response = http_response_404()
elif template_name == "模板502":
template_response = http_response_502()
# 处理生成操作
if 'generate' in request.form:
request_body = request.form.get('request_body', '')
response_body = request.form.get('response_body', '')
file_name = request.form.get('file_name', '')
# 执行PCAP文件生成
fixs = fix_content_length(request_body)
file_path = creat_http_pcap(fixs, response_body, pcapname=file_name)
# 提取文件名,假设file_path是完整的文件路径
filename = os.path.basename(file_path)
# 重定向到下载路由
return redirect(url_for('generate_pcap.download_file', filename=filename))
# return redirect(url_for('generate_pcap.generate'))
return render_template('generate_pcap.html', template_response=template_response,
request_body_content=request_body)
@generate_pcap.route('/generate_pcap/template')
def template():
template_name = request.args.get('name')
if template_name == "标准GET":
return standard_get()
elif template_name == "普通POST":
return ordinary_post()
elif template_name == "FORM提交":
return form_submission()
else:
return "模板不存在", 404
@generate_pcap.route('/download/<filename>')
def download_file(filename):
# 假设所有生成的.pcap文件都保存在一个名为'generated_pcaps'的目录下
directory = os.path.join(os.getcwd(), 'pcapss')
return send_from_directory(directory, filename, as_attachment=True)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。