dump XML data to a file
(host, output, is_xml=True)
| 84 | |
| 85 | |
| 86 | def write_data(host, output, is_xml=True): |
| 87 | """ |
| 88 | dump XML data to a file |
| 89 | """ |
| 90 | if not os.path.exists(lib.settings.NMAP_XML_OUTPUT_BACKUP if is_xml else lib.settings.NMAP_JSON_OUTPUT_BACKUP): |
| 91 | os.makedirs(lib.settings.NMAP_XML_OUTPUT_BACKUP if is_xml else lib.settings.NMAP_JSON_OUTPUT_BACKUP) |
| 92 | file_path = "{}/{}_{}.{}".format( |
| 93 | lib.settings.NMAP_XML_OUTPUT_BACKUP if is_xml else lib.settings.NMAP_JSON_OUTPUT_BACKUP, |
| 94 | str(host), lib.jsonize.random_file_name(length=10), "xml" if is_xml else "json" |
| 95 | ) |
| 96 | with open(file_path, 'a+') as results: |
| 97 | if is_xml: |
| 98 | results.write(output) |
| 99 | else: |
| 100 | json.dump(output, results, indent=4) |
| 101 | return file_path |
| 102 | |
| 103 | |
| 104 | def find_nmap(search_paths): |