From 9c098715c68871783336750cc8d8a80390ca70a7 Mon Sep 17 00:00:00 2001 From: Danila Vershinin Date: Fri, 31 May 2024 12:58:56 +0800 Subject: [PATCH] Update Tor exit nodes source and improve IP filtering The source of the Tor exit nodes list has been changed to use torproject.org for IPv4 and openinternet.io for IPv6 due to the fact that torproject.org does not provide IPv6 list. In addition, added logic to filter out IPv4 addresses and comments from IPv6 list. This ensures accuracy and reliability of the lists being obtained. --- fds/WebClient.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fds/WebClient.py b/fds/WebClient.py index 8518411..7ffc5f2 100644 --- a/fds/WebClient.py +++ b/fds/WebClient.py @@ -100,12 +100,23 @@ def get_country_networks(self, country): return content.splitlines() def get_tor_exits(self, family=4): - url = 'https://lists.fissionrelays.net/tor/exits-ipv{}.txt'.format(family) - log.debug('Downloading {}'.format(url)) + """Get a list of Tor exit nodes.""" + # Use torproject.org for IPv4 list + url = 'https://check.torproject.org/torbulkexitlist' + if family == 6: + # torproject.org does not provide IPv6 list + # https://gitlab.torproject.org/tpo/core/tordnsel/-/issues/24034 + url = 'https://openinternet.io/tor/tor-exit-list.txt' + + log.debug('Downloading IPv%s exit nodes list from %s', family, url) content = self.download_file( url, display_name='Tor IPv{} exits list'.format(family), local_filename='/var/lib/fds/tor-{}.zone'.format(family), return_type='contents' ) - return content.splitlines() + ips = content.splitlines() + # For IPv6 list, we need to remove IPv4 addresses and comments '#' + if family == 6: + ips = [ip for ip in ips if ':' in ip and not ip.startswith('#')] + return ips