Skip to content

Commit 2e64395

Browse files
committed
Added in exclusion functionality
1 parent 28bb9be commit 2e64395

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

Interlace/lib/core/input.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ def process_commands(arguments):
6161
commands = set()
6262
ranges = set()
6363
targets = set()
64+
exclusions_ranges = set()
65+
exclusions = set()
6466
final_commands = set()
6567
output = OutputHelper(arguments)
6668

69+
print(arguments.exclusions)
70+
6771
if "," in arguments.port:
6872
ports = arguments.port.split(",")
6973
elif "-" in arguments.port:
@@ -80,6 +84,13 @@ def process_commands(arguments):
8084
for target in arguments.target_list:
8185
ranges.add(target.strip())
8286

87+
# process exclusions first
88+
if arguments.exclusions:
89+
exclusions_ranges.add(arguments.exclusions)
90+
else:
91+
for exclusion in arguments.exclusions_list:
92+
exclusions_ranges.add(target.strip())
93+
8394
# removing elements that may have spaces (helpful for easily processing comma notation)
8495
for target in ranges:
8596
target = target.replace(" ", "")
@@ -97,6 +108,25 @@ def process_commands(arguments):
97108
else:
98109
targets.add(ips)
99110

111+
# removing elements that may have spaces (helpful for easily processing comma notation)
112+
for exclusion in exclusions_ranges:
113+
exclusion = exclusion.replace(" ", "")
114+
115+
for ips in exclusion.split(","):
116+
# checking for CIDR
117+
if not arguments.nocidr and "/" in ips:
118+
exclusions.update(InputHelper._get_cidr_to_ips(ips))
119+
# checking for IPs in a range
120+
elif "-" in ips:
121+
exclusions.update(InputHelper._get_ips_from_range(ips))
122+
# checking for glob ranges
123+
elif "*" in ips:
124+
exclusions.update(InputHelper._get_ips_from_glob(ips))
125+
else:
126+
exclusions.add(ips)
127+
128+
targets -= exclusions
129+
100130
if arguments.command:
101131
commands.add(arguments.command)
102132
else:
@@ -140,7 +170,7 @@ def setup_parser():
140170
targets.add_argument(
141171
'-t', dest='target', required=False,
142172
help='Specify a target or domain name either in comma format, '
143-
'CIDR notation, or a single target.'
173+
'CIDR notation, glob notation, or a single target.'
144174
)
145175

146176
targets.add_argument(
@@ -150,6 +180,22 @@ def setup_parser():
150180
type=lambda x: InputHelper.readable_file(parser, x)
151181
)
152182

183+
# exclusions group
184+
exclusions = parser.add_mutually_exclusive_group()
185+
186+
exclusions.add_argument(
187+
'-e', dest='exclusions', required=False,
188+
help='Specify an exclusion either in comma format, '
189+
'CIDR notation, or a single target.'
190+
)
191+
192+
exclusions.add_argument(
193+
'-eL', dest='exclusions_list', required=False,
194+
help='Specify a list of exclusions.',
195+
metavar="FILE",
196+
type=lambda x: InputHelper.readable_file(parser, x)
197+
)
198+
153199
parser.add_argument(
154200
'-threads', dest='threads', required=False,
155201
help="Specify the maximum number of threads to run (DEFAULT:5)",

0 commit comments

Comments
 (0)