From b9e2d0414caf2c8c6693c87289067915c6ac13f4 Mon Sep 17 00:00:00 2001 From: Kirill Zhdanov Date: Wed, 24 Jan 2024 23:08:01 +0700 Subject: [PATCH] refactor: feat: fully fletged Cartesian product of digits --- src/pnk/__init__.py | 2 +- src/pnk/__main__.py | 2 +- src/pnk/core.py | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/pnk/__init__.py b/src/pnk/__init__.py index fee46bd..5becc17 100755 --- a/src/pnk/__init__.py +++ b/src/pnk/__init__.py @@ -1 +1 @@ -__version__ = "0.11.1" +__version__ = "1.0.0" diff --git a/src/pnk/__main__.py b/src/pnk/__main__.py index 52a67af..47f7c43 100755 --- a/src/pnk/__main__.py +++ b/src/pnk/__main__.py @@ -17,7 +17,7 @@ def setup_argparse(): # optional argument group = parser.add_mutually_exclusive_group() group.add_argument('-i', '--increment', action='store_true', help='increment any one or two digits on subdomains') - group.add_argument('-c', '--cartesian', action='store_true', help='increment digits on subdomains creating Cartesian product') + group.add_argument('-c', '--cartesian', action='store_true', help='increment digits on subdomains creating their Cartesian product') # positional argument parser.add_argument( 'file', diff --git a/src/pnk/core.py b/src/pnk/core.py index 9503989..2d1441c 100755 --- a/src/pnk/core.py +++ b/src/pnk/core.py @@ -3,7 +3,9 @@ import itertools import pathlib import re +from collections import deque from urllib.parse import urlparse + from pnk.helpers import logger log = logger.get_logger() @@ -82,6 +84,14 @@ def incrmt(self, subdomain): log.debug("No digits found!") yield subdomain + def join_product_tuples(self, tuples): + _len = len(tuples) + log.debug(_len) + log.debug(tuples) + if _len == 1: + return "".join(*tuples) + return "".join(tuples[0]) + "." + self.join_product_tuples(tuples[1:]) + def run(self): """Compose functions on files with hostname lines""" for lines in self.file: @@ -100,8 +110,35 @@ def run(self): print(".".join(_s) + "." + d) _s[index] = j if self.args.cartesian: - for p in itertools.product(*map(self.incrmt, s)): - print(".".join(p) + "." + d) + _deque = deque() + subs_list = [] + pattern = re.compile('((?