Skip to content

Commit

Permalink
fix(CornerShot): Improved add_shots performance, now user needs to "l…
Browse files Browse the repository at this point in the history
…ock_and_load" before calling "open_fire"
  • Loading branch information
sagiesec committed Feb 3, 2021
1 parent 1f84dc1 commit 0a27808
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Adding carriers, target and ports is achieved via the *add_shots* method. Once r
from cornershot import CornerShot
cs = CornerShot("username", "password", "fqdn")
cs.add_shots(carriers=["192.168.1.1"],targets=["192.168.1.2","192.168.1.3"])
cs.lock_and_load()
results = cs.open_fire()
```

Expand Down
1 change: 1 addition & 0 deletions cornershot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def parse_port_ranges(ranges):

cs = CornerShot(args.user, args.password, args.domain, workers=args.threads)
cs.add_shots(parse_ip_ranges(args.carrier), parse_ip_ranges(args.target), target_ports=parse_port_ranges(args.tports))
cs.lock_and_load()
cs.open_fire()

except KeyboardInterrupt:
Expand Down
7 changes: 4 additions & 3 deletions cornershot/cornershot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def add_shots(self, destinations, targets, target_ports=None, destination_ports=
else:
self.shot_gen = self._shots_generator(destinations, targets, target_ports, destination_ports)

self.shot_gen, sg_sum = itertools.tee(self.shot_gen)
self.total_shots = sum(1 for _ in sg_sum)

def _shots_generator(self, destinations, targets, target_ports, destination_ports=None):
for destination in destinations:
for target in targets:
Expand Down Expand Up @@ -141,6 +138,10 @@ def open_fire(self,blocking=True):
main_thread = threading.Thread(target=self._shots_manager,daemon=True)
main_thread.start()

def lock_and_load(self):
self.shot_gen, sg_sum = itertools.tee(self.shot_gen)
self.total_shots = sum(1 for _ in sg_sum)

def read_results(self):
return self.results

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
setup(
name='cornershot',
python_requires='>=3',
version='0.1.8',
version='0.2.0',
description='Library to test network connectivity',
long_description_content_type='text/markdown',
long_description=long_description,
Expand Down

0 comments on commit 0a27808

Please sign in to comment.