added 'antifilter' source

This commit is contained in:
Pavel Muhortov 2023-09-03 13:00:17 +03:00
parent 7375df5a2c
commit 8b2b1d3de0
2 changed files with 69 additions and 0 deletions

View File

@ -34,6 +34,12 @@ amazon = true
# - contain only atlassian ip ranges
atlassian = true
#
# antifilter - it's a parsed RKN block list (https://antifilter.network/download/ipsmart.lst)
# + absoutely free
# + simple parsing
# - it's necessary only in Russia
antifilter = true
#
# herrbischoff - it's a GitHub repository (https://github.com/herrbischoff/country-ip-blocks)
# + absoutely free
# + updated hourly

View File

@ -432,6 +432,12 @@ class Route(Connect):
force_download=force_download,
logger_alias=logger_alias
)
elif name == 'antifilter':
return self.__update_source_antifilter(
db_root_path=db_root_path,
force_download=force_download,
logger_alias=logger_alias
)
elif name == 'atlassian':
return self.__update_source_atlassian(
db_root_path=db_root_path,
@ -664,6 +670,63 @@ class Route(Connect):
return True
return False
def __update_source_antifilter(
self,
db_root_path: str,
force_download: bool = False,
logger_alias: str = inspect.stack()[0].function
) -> bool:
local_logger = logging.getLogger(logger_alias)
if Do.args_valid(locals(), self.__update_source_antifilter.__annotations__):
db_source_url = "https://antifilter.network/download/ipsmart.lst"
db_source_name = "antifilter"
db_source_root = db_root_path + sep + "sources" + sep + db_source_name
db_source_file = db_source_root + sep + "ipsmart.lst"
db_source_cidr_root = db_source_root + sep + "cidr"
if not path.exists(db_source_file):
force_download = True
if force_download:
if not self.__download_db(
url=db_source_url,
dst=db_source_file,
logger_alias=logger_alias
):
return False
with open(db_source_file, mode='r', encoding='utf-8') as db_source_raw:
db_source_data = db_source_raw.read().splitlines()
db_parsed_data_ipv4 = []
db_parsed_data_ipv6 = []
for item in db_source_data:
if not ":" in item:
db_parsed_data_ipv4.append(item)
else:
db_parsed_data_ipv6.append(item)
makedirs(db_source_cidr_root + sep + "ipv4", exist_ok=True)
db_source_cidr_ipv4_file = (""
+ db_source_cidr_root + sep + "ipv4"
+ sep + db_source_name + ".cidr"
)
with open(db_source_cidr_ipv4_file, mode='w+', encoding='utf-8') as cidr_dump:
cidr_dump.write('\n'.join(db_parsed_data_ipv4))
local_logger.info(msg=db_source_cidr_ipv4_file + ' saved')
makedirs(db_source_cidr_root + sep + "ipv6", exist_ok=True)
db_source_cidr_ipv6_file = (""
+ db_source_cidr_root + sep + "ipv6"
+ sep + db_source_name + ".cidr"
)
with open(db_source_cidr_ipv6_file, mode='w+', encoding='utf-8') as cidr_dump:
cidr_dump.write('\n'.join(db_parsed_data_ipv6))
local_logger.info(msg=db_source_cidr_ipv6_file + ' saved')
return True
return False
def __update_source_herrbischoff(
self,
db_root_path: str,