From eac7ff35ec7384685192553f53aa507e940e19bc Mon Sep 17 00:00:00 2001 From: Ground-Zerro Date: Thu, 28 Mar 2024 14:28:44 +1100 Subject: [PATCH] update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Принудительное чтение и запись файлов в 'utf-8-sig' помогло решить проблему неправильного распознавания некоторых DNS имен из списков на разных ОС. --- config.txt | 2 +- main.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config.txt b/config.txt index 589a1d8..572d794 100644 --- a/config.txt +++ b/config.txt @@ -21,7 +21,7 @@ threads = filetype = # адрес шлюза - используется, только если опция "filetype" установлена в 'win' или пользователь выбрал такой формат выходного файла -# если не указан, будет использоваться значение по умолчанию (0.0.0.0.0) +# если не указан, будет использоваться значение по умолчанию (0.0.0.0) gateway = # Команда для консоли после завершения скриптом всех операций diff --git a/main.py b/main.py index c2206d1..077374e 100644 --- a/main.py +++ b/main.py @@ -182,7 +182,7 @@ def main(): os.remove(outfilename) # DNS resolution for selected services - with open(outfilename, 'w') as file: # Open file for writing + with open(outfilename, 'w', encoding='utf-8-sig') as file: # Open file for writing for service in selected_services: result = resolve_dns_and_write(service, urls[service], unique_ips_all_services, include_cloudflare, threads) file.write(result) # Write unique IPs directly to the file @@ -198,9 +198,9 @@ def main(): outfilename_format = input("\nВыберите в каком формате сохранить файл: \n\033[32mwin\033[0m - 'route add %IP% mask %mask% %gateway%', \033[32mvlsm\033[0m - 'IP/mask', \033[32mEnter\033[0m - только IP: ") if outfilename_format.lower() == 'vlsm': # Handle VLSM format here - with open(outfilename, 'r') as file: + with open(outfilename, 'r', encoding='utf-8-sig') as file: ips = file.readlines() - with open(outfilename, 'w') as file: + with open(outfilename, 'w', encoding='utf-8-sig') as file: for ip in ips: file.write(f"{ip.strip()}/32\n") # Assuming /32 subnet mask for all IPs elif outfilename_format.lower() == 'win': @@ -208,9 +208,9 @@ def main(): gateway_input = input(f"Укажите шлюз (\033[32mEnter\033[0m - {gateway}): ") if gateway_input: gateway = gateway_input.strip() - with open(outfilename, 'r') as file: + with open(outfilename, 'r', encoding='utf-8-sig') as file: ips = file.readlines() - with open(outfilename, 'w') as file: + with open(outfilename, 'w', encoding='utf-8-sig') as file: for ip in ips: file.write(f"route add {ip.strip()} mask 255.255.255.255 {gateway}\n") else: @@ -225,9 +225,9 @@ def main(): file.write(f"{ip.strip()}/32\n") # Assuming /32 subnet mask for all IPs elif filetype.lower() == 'win': # Handle Windows format if specified in the configuration file - with open(outfilename, 'r') as file: + with open(outfilename, 'r', encoding='utf-8-sig') as file: ips = file.readlines() - with open(outfilename, 'w') as file: + with open(outfilename, 'w', encoding='utf-8-sig') as file: for ip in ips: file.write(f"route add {ip.strip()} mask 255.255.255.255 {gateway}\n")