1
0
Fork
You've already forked blocktor
0
block sign ups from Tor exit nodes
  • Python 100%
2026年06月09日 12:17:33 +02:00
block_tor_ips.py fix: use /128 for IPv6 instead of /32 2026年06月09日 12:17:33 +02:00
LICENSE first commit 2026年04月21日 13:55:40 +02:00
README.md Updated 2026年04月21日 13:59:45 +02:00
requirements.txt first commit 2026年04月21日 13:55:40 +02:00

Block Tor Exit Nodes & Mullvad VPN for Mastodon

A Python script that automatically downloads and blocks Tor exit nodes and Mullvad VPN IP ranges in your Mastodon server via the admin API, avoiding sign ups from them.

Features

  • Automatically blocks Tor exit nodes from multiple trusted sources
  • Blocks known Mullvad VPN IP ranges (ASN AS39351)
  • Configurable severity levels (sign_up_block, sign_up_requires_approval, no_access)
  • Dry-run mode to test without making changes
  • Respects Mastodon API rate limits automatically
  • Handles pagination for existing blocks
  • Detailed logging with Loguru
  • Asynchronous operations for better performance
  • Automatic retry with exponential backoff

Prerequisites

  • Python 3.7+
  • Mastodon instance with admin access
  • Admin API token

Installation

  1. Clone the repository or download the script:
git clone <repository-url>
cd <repository-directory>
  1. Create the Python Virtual Environment:
python -m venv .
  1. Activate it:
source bin/activate
  1. Install the required dependencies:
pip install -r requirements.txt

Configuration

Environment Variables Create a .env file in the script directory and fill it with your data:

MASTODON_URL=https://your-mastodon-instance.com
MASTODON_TOKEN=your_admin_api_token_here

Getting a Mastodon Admin Token

  1. Log into your Mastodon instance as an admin user
  2. Go to Preferences → Development
  3. Click "New Application"
  4. Fill in the application name (e.g., "IP Blocker")
  5. Grant the following scopes:

admin:read (to view existing blocks) admin:write (to create new blocks)

  1. Click "Submit"
  2. Copy the access token shown

Configuration Variables in Script You can modify these variables directly in the script:

# Block severity level
SEVERITY = "sign_up_block" # Options: "sign_up_block", "sign_up_requires_approval", "no_access"
# Custom comment for blocks
COMMENT = "Tor exit node / Mullvad VPN - bloc automàtic"
# Dry run mode (can also use --dry-run flag)
DRY_RUN = "--dry-run" in sys.argv

Severity Levels Explained

sign_up_block: Completely blocks sign-ups from these IPs sign_up_requires_approval: Allows sign-ups but requires admin approval no_access: Blocks all access (including browsing)

Usage

Basic Execution

python3 block_tor_ips.py

Dry Run (Test Mode)

python3 block_tor_ips.py --dry-run

This will simulate the blocking process without actually creating any blocks, showing you what would be blocked.

Setting Up as a Cron Job (Automated) To run the script automatically every day:

crontab -e

Add the following line to run daily at 2 AM:

0 2 * * * cd /path/to/script && /usr/bin/python3 block_tor_ips.py >> /var/log/tor_blocker.log 2>&1