Skip to content

Commit

Permalink
Update Tor exit nodes source and improve IP filtering
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dvershinin committed May 31, 2024
1 parent 5172c8d commit 9c09871
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions fds/WebClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9c09871

Please sign in to comment.