()
Main function of the script.
Main function of the script.
Main function of the script .
def main():
    """Main function of the script."""
    for filename in args.filename:

        # Checks the file path
        if not os.path.exists(filename):
            parser.print_help()
            print("\n[-] The file {} cannot be found or you do not have "
                  "permission to open the file.".format(filename))
            continue

        if not args.skip_entity_check:
            # Read the file and check for entities
            with open(filename) as fh:
                contents = fh.read()
                if '<!entity' in contents.lower():
                    print("[-] Error! This program does not permit XML "
                          "entities. Ignoring {}".format(filename))
                    print("[*] Use -s (--skip_entity_check) to ignore this "
                          "check for XML entities.")
                    continue
        data = parse_xml(filename)
        if not data:
            print("[*] Zero hosts identitified as 'Up' or with 'open' ports. "
                  "Use the -u option to display ports that are 'open|filtered'. "
                  "Exiting.")
            exit()
        if args.csv:
            parse_to_csv(data)
        if args.ip_addresses:
            addrs = list_ip_addresses(data)
            for addr in addrs:
                print(addr)
        if args.print_all:
            print_data(data)
        if args.filter_by_port:
            print_filtered_port(data, args.filter_by_port)
        if args.print_web_ports:
            print_web_ports(data)
        if args.least_common_ports:
            print("\n{} LEAST COMMON PORTS".format(filename.upper()))
            least_common_ports(data, args.least_common_ports)
        if args.most_common_ports:
            print("\n{} MOST COMMON PORTS".format(filename.upper()))
            most_common_ports(data, args.most_common_ports)
def main ( ) : for filename in args . filename : # Checks the file path if not os . path . exists ( filename ) : parser . print_help ( ) print ( "\n[-] The file {} cannot be found or you do not have " "permission to open the file." . format ( filename ) ) continue if not args . skip_entity_check : # Read the file and check for entities with open ( filename ) as fh : contents = fh . read ( ) if '<!entity' in contents . lower ( ) : print ( "[-] Error! This program does not permit XML " "entities. Ignoring {}" . format ( filename ) ) print ( "[*] Use -s (--skip_entity_check) to ignore this " "check for XML entities." ) continue data = parse_xml ( filename ) if not data : print ( "[*] Zero hosts identitified as 'Up' or with 'open' ports. " "Use the -u option to display ports that are 'open|filtered'. " "Exiting." ) exit ( ) if args . csv : parse_to_csv ( data ) if args . ip_addresses : addrs = list_ip_addresses ( data ) for addr in addrs : print ( addr ) if args . print_all : print_data ( data ) if args . filter_by_port : print_filtered_port ( data , args . filter_by_port ) if args . print_web_ports : print_web_ports ( data ) if args . least_common_ports : print ( "\n{} LEAST COMMON PORTS" . format ( filename . upper ( ) ) ) least_common_ports ( data , args . least_common_ports ) if args . most_common_ports : print ( "\n{} MOST COMMON PORTS" . format ( filename . upper ( ) ) ) most_common_ports ( data , args . most_common_ports )