Skip to content

Commit

Permalink
Added an option to compress the created hosts file.
Browse files Browse the repository at this point in the history
In particular, the compression option removes non-necessary lines (empty lines and comments) and puts multiple domains in each line.
This option should solve the issue StevenBlack#411 regarding the DNS client service of Windows.
  • Loading branch information
Stefano committed Dec 30, 2017
1 parent ce8d3ab commit ff9e05f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions updateHostsFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,10 @@ def create_initial_file():

def compress_file(input_file, target_ip, output_file):
"""
Reduce the file dimension removing non-necessary lines (empty lines and comments) and putting multiple domains in each line.
Reducing the number of lines of the file, the parsing under Microsoft Windows is much faster.
Reduce the file dimension removing non-necessary lines (empty lines and
comments) and putting multiple domains in each line.
Reducing the number of lines of the file, the parsing under Microsoft
Windows is much faster.
Parameters
----------
Expand All @@ -672,8 +674,8 @@ def compress_file(input_file, target_ip, output_file):
continue

if line.startswith(target_ip):
l = len(lines[lines_index])
if l < 128 and (l + len(line[7:])) < 192:
current_len = len(lines[lines_index])
if current_len < 128 and (current_len + len(line[7:])) < 192:
lines[lines_index] += line[7:-1]
else:
lines[lines_index] += '\n'
Expand All @@ -700,7 +702,8 @@ def remove_dups_and_excl(merge_file, exclusion_regexes, output_file=None):
exclusion_regexes : list
The list of regex patterns used to exclude domains.
output_file : file
The file object in which the result is written. If None, the file 'settings["outputpath"]' will be created.
The file object in which the result is written. If None, the file
'settings["outputpath"]' will be created.
"""

number_of_rules = settings["numberofrules"]
Expand Down

0 comments on commit ff9e05f

Please sign in to comment.