Skip to content

Commit 67da487

Browse files
committed
Removed unused code and fixed IP issue
1 parent f38bb59 commit 67da487

File tree

1 file changed

+14
-41
lines changed

1 file changed

+14
-41
lines changed

Interlace/lib/core/input.py

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,6 @@ def _get_files_from_directory(arg):
4747

4848
return files
4949

50-
@staticmethod
51-
def _get_ips_from_range(ip_range):
52-
ips = set()
53-
ip_range = ip_range.split("-")
54-
55-
# parsing the above structure into an array and then making into an IP address with the end value
56-
end_ip = ".".join(ip_range[0].split(".")[0:-1]) + "." + ip_range[1]
57-
58-
# creating an IPRange object to get all IPs in between
59-
range_obj = IPRange(ip_range[0], end_ip)
60-
61-
for ip in range_obj:
62-
ips.add(str(ip))
63-
64-
return ips
65-
66-
@staticmethod
67-
def _get_ips_from_glob(glob_ips):
68-
ip_glob = IPGlob(glob_ips)
69-
70-
ips = set()
71-
72-
for ip in ip_glob:
73-
ips.add(str(ip))
74-
75-
return ips
76-
77-
@staticmethod
78-
def _get_cidr_to_ips(cidr_range):
79-
(ip, cidr) = cidr_range.split("/")
80-
mask = 32 - int(cidr)
81-
first_ip = struct.unpack(">I", socket.inet_aton(ip))[0]
82-
last_ip = first_ip | ((1 << mask) - 1)
83-
ips = frozenset([socket.inet_ntoa(struct.pack('>I', x)) for x in range(first_ip, last_ip)])
84-
return ips
85-
8650
@staticmethod
8751
def _process_port(port_type):
8852
if "," in port_type:
@@ -215,8 +179,9 @@ def pre_process_target_spec(target_spec):
215179
target_specs = itertools.chain(*target_specs)
216180

217181
def parse_and_group_target_specs(target_specs, nocidr):
182+
# issue #131 lies here
218183
str_targets = set()
219-
ipset_targets = IPSet()
184+
ips_list = list()
220185
for target_spec in target_specs:
221186
if (
222187
target_spec.startswith(".") or
@@ -233,9 +198,16 @@ def parse_and_group_target_specs(target_specs, nocidr):
233198
elif "*" in target_spec:
234199
target_spec = glob_to_iprange(target_spec)
235200
else: # str IP addresses and str CIDR notations
236-
target_spec = (target_spec,)
237-
ipset_targets.update(IPSet(target_spec))
238-
return (str_targets, ipset_targets)
201+
if "/" in target_spec:
202+
# CIDR
203+
target_spec = IPSet((target_spec,))
204+
else:
205+
target_spec = [target_spec]
206+
207+
for i in target_spec:
208+
ips_list.append(str(i))
209+
print(f"updating: {target_spec}")
210+
return (str_targets, set(ips_list))
239211

240212
str_targets, ipset_targets = parse_and_group_target_specs(
241213
target_specs=target_specs,
@@ -259,6 +231,7 @@ def parse_and_group_target_specs(target_specs, nocidr):
259231
target_specs=exclusion_specs,
260232
nocidr=arguments.nocidr,
261233
)
234+
262235
str_targets -= str_exclusions
263236
ipset_targets -= ipset_exclusions
264237

@@ -279,7 +252,7 @@ def process_data_for_tasks_iterator(arguments):
279252
str_targets, ipset_targets = InputHelper._process_targets(
280253
arguments=arguments,
281254
)
282-
targets_count = len(str_targets) + ipset_targets.size
255+
targets_count = len(str_targets) + len(ipset_targets)
283256

284257
if not targets_count:
285258
raise Exception("No target provided, or empty target list")

0 commit comments

Comments
 (0)