From 3b80713471e3fdefa4cdc92d9acb38f379986cb7 Mon Sep 17 00:00:00 2001 From: Jake Miller Date: Mon, 23 Jul 2018 20:14:13 -0500 Subject: [PATCH] Checks for XML entities. --- nmap_xml_parser.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/nmap_xml_parser.py b/nmap_xml_parser.py index a21ec6a..e3fadaf 100644 --- a/nmap_xml_parser.py +++ b/nmap_xml_parser.py @@ -17,21 +17,15 @@ import os import csv import argparse from collections import Counter -from sys import version from time import sleep -if not version.startswith('3'): - print('\nThis script is intended to be run with Python3. If using another version and encounter an error, try using Python3\n') - sleep(3) - - def get_xml_root(xml): """Parses an xml file and returns the tree.""" try: tree = etree.parse(xml) except Exception as error: - print("A an error occurred. The XML may not be well formed. Please review the error and try again: {}".format(error)) + print("[-] A an error occurred. The XML may not be well formed. Please review the error and try again: {}".format(error)) exit() return tree.getroot() @@ -140,7 +134,7 @@ def parse_to_csv(data): print(' '.join(item)) exit() csv_writer = csv.writer(csv_file) - print('\n [+] {} exists. Appending to file!\n'.format(csv_name)) + print('\n[+] {} exists. Appending to file!\n'.format(csv_name)) for item in data: csv_writer.writerow(item) csv_file.close() @@ -234,6 +228,7 @@ def print_data(data): def main(): + """Main function of the script.""" for filename in args.filename: # Checks the file path @@ -249,6 +244,9 @@ def main(): print("[-] Error! This program does not permit XML entities. Exiting!") exit() data = parse_xml(filename) + if not data: + print("[*] Zero hosts identitified as 'Up'. Exiting.") + exit() if args.csv: parse_to_csv(data) if args.ip_addresses: