Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行批量查询数据时执行:txt文本中,ip="211.45.30.16/24",生成表格出现异常 #19

Open
OKVVbin opened this issue May 25, 2023 · 3 comments

Comments

@OKVVbin
Copy link

OKVVbin commented May 25, 2023

91684985709_ pic
Traceback (most recent call last):
File "/Users/PycharmProjects/FofaMap/project/lib/python3.10/site-packages/xlsxwriter/workbook.py", line 324, in close
self._store_workbook()
File "/Users/PycharmProjects/FofaMap/project/lib/python3.10/site-packages/xlsxwriter/workbook.py", line 659, in _store_workbook
raise e
File "/Users/PycharmProjects/FofaMap/project/lib/python3.10/site-packages/xlsxwriter/workbook.py", line 656, in _store_workbook
xlsx_file = ZipFile(self.filename, "w", compression=ZIP_DEFLATED,
File "/Users/.pyenv/versions/3.10.4/lib/python3.10/zipfile.py", line 1249, in init
self.fp = io.open(file, filemode)
FileNotFoundError: [Errno 2] No such file or directory: 'task-2-【ip="211.45.30.16/24"】.xlsx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/PycharmProjects/FofaMap/fofa_search.py", line 631, in
bat_query(bat_query_file, scan_format)
File "/Users/PycharmProjects/FofaMap/fofa_search.py", line 386, in bat_query
out_file_excel(filename, database, scan_format, fields)
File "/Users/PycharmProjects/FofaMap/fofa_search.py", line 227, in out_file_excel
workbook.close()
File "/Users/PycharmProjects/FofaMap/project/lib/python3.10/site-packages/xlsxwriter/workbook.py", line 326, in close
raise FileCreateError(e)
xlsxwriter.exceptions.FileCreateError: [Errno 2] No such file or directory: 'task-2-【ip="211.45.30.16/24"】.xlsx'

@OKVVbin
Copy link
Author

OKVVbin commented May 25, 2023

初步断定/无法存在于文件名的问题

@OKVVbin
Copy link
Author

OKVVbin commented May 25, 2023

加一个函数过滤一下:
修改后的代码(添加了sanitize_filename函数,修改了out_file_excel函数):
def sanitize_filename(filename):
valid_chars = f'-.()【】= {string.ascii_letters}{string.digits}"'
valid_chars += ''.join(chr(i) for i in range(0x4E00, 0x9FA6) if unicodedata.category(chr(i)).startswith('L'))
return ''.join(c if c in valid_chars else '
' for c in filename)

def out_file_excel(filename, database, scan_format, fields):
print(colorama.Fore.RED + "======文档输出=======")
if scan_format:
# 输出扫描格式文档
out_file_scan(filename, database)
else:
field = fields.split(",") # 获取查询参数
column_lib = {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'F', 7: 'G', 8: 'H', 9: 'I', 10: 'J', 11: 'K', 12: 'L',
13: 'M', 14: 'N', 15: 'O', 16: 'P', 17: 'Q', 18: 'R', 19: 'S', 20: 'T', 21: 'U', 22: 'V', 23: 'W',
24: 'X', 25: 'Y', 26: 'Z'}
sanitized_filename = sanitize_filename(filename) # 替换无效字符
workbook = xlsxwriter.Workbook(sanitized_filename)
worksheet = workbook.add_worksheet()
worksheet.set_column('A:{}'.format(column_lib[len(field)]), 30)
title_format = workbook.add_format(
{'font_size': 14, 'border': 1, 'bold': True, 'font_color': 'white', 'bg_color': '#4BACC6',
'align': 'center',
'valign': 'center', 'text_wrap': True})
content_format = workbook.add_format({'border': 1, 'align': 'left', 'valign': 'vcenter', 'text_wrap': True})
i = 1
row = 1
col = 0

    for column in field:
        worksheet.write('{}1'.format(column_lib[i]), column, title_format)
        i += 1
    for item in database:
        for n in range(len(field)):
            worksheet.write(row, col + n, item[n], content_format)
        row = row + 1
    workbook.close()
    print(colorama.Fore.GREEN + "[+] 文档输出成功!文件名为:{}".format(sanitized_filename))

@asaotomo
Copy link
Owner

感谢您对FofaMap的支持。目前Bug已定位,报错确实是因为生成的xlsx文件名含有特殊符号导致,我们将在下一个版本中针对该问题进行优化。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants