@@ -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