Skip to content

Commit aea40a7

Browse files
committed
creates a way to clean duplicate IP's out of the hosts file from the terminal
1 parent 5f5954a commit aea40a7

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

api_calls/honeyscore_hook.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import requests
2-
from bs4 import BeautifulSoup
32

43

54
class HoneyHook(object):

lib/banner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import random
33

4-
VERSION = "3.1.2"
4+
VERSION = "3.1.3"
55

66

77
def banner_1(line_sep="#--", space=" " * 30):

lib/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def complete_text(self, text, state):
5555
tokens/reset Reset API tokens if needed
5656
external View loaded external commands
5757
ver[sion] View the current version of the program
58+
clean/clear Clean the hosts.txt file of duplicate IP addresses
5859
help/? Display this help
5960
"""
6061

lib/term/terminal.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class object for the main terminal of the program
4545
"reset", "tokens",
4646
# show the version number
4747
"ver", "version",
48+
# clean the hosts file of duplicate IP's
49+
"clean", "clear",
4850
# easter eggs!
4951
"idkwhatimdoing", "ethics", "skid"
5052
]
@@ -148,6 +150,25 @@ def do_terminal_command(self, command):
148150
"""
149151
lib.settings.cmdline(command, is_msf=False)
150152

153+
def do_clean_hosts(self):
154+
"""
155+
Clean the hosts.txt file of any duplicate IP addresses
156+
"""
157+
retval = set()
158+
current_size = len(self.loaded_hosts)
159+
for host in self.loaded_hosts:
160+
retval.add(host)
161+
cleaned_size = len(retval)
162+
with open(lib.settings.HOST_FILE, 'w') as hosts:
163+
for item in list(retval):
164+
hosts.write(item)
165+
if current_size != cleaned_size:
166+
lib.output.info("cleaned {} duplicate IP address(es) (total of {})".format(
167+
current_size - cleaned_size, cleaned_size
168+
)
169+
)
170+
self.__reload()
171+
151172
def do_token_reset(self, api, token, username):
152173
"""
153174
Explanation:
@@ -475,6 +496,8 @@ def terminal_main_display(self, tokens, extra_commands=None, save_history=True):
475496
self.do_view_gathered()
476497
elif any(c in choice for c in ("ver", "version")):
477498
self.do_show_version_number()
499+
elif any(c in choice for c in ("clean", "clear")):
500+
self.do_clean_hosts()
478501
elif "single" in choice:
479502
try:
480503
if "help" in choice_data_list:

0 commit comments

Comments
 (0)