A simple way to ban a IP/Prefix/or entire ASN using NF Tables!
Find a file
2025-12-11 14:49:10 -05:00
debian-installer.sh added github back they unbanned me 2025-12-11 14:49:10 -05:00
LICENSE removed all github stuff 2025-12-11 01:28:15 -05:00
README.md added github back they unbanned me 2025-12-11 14:49:10 -05:00
service.py removed all github stuff 2025-12-11 01:28:15 -05:00

BAN4ASN

License: MIT Platform Language Status Debian CLI nftables


📌 Overview

BAN4ASN is a powerful, crossplatform security tool that allows administrators to:

  • Identify the ASN for any IP, prefix, or ASN number
  • Retrieve live prefix announcements from RIPE
  • Automatically generate nftables firewall rules to block entire ASNs
  • Deploy rules automatically on Debian systems
  • Install a standalone CLI binary for automated operations
  • Unblock previously applied rules
  • Use the tool across Windows, macOS, and Linux
  • Enjoy fast, dependencyfree operation except for Python and requests

Developed and maintained by TechOtter, licensed under the MIT License.


🚀 Features

🔍 Lookup features

  • IP → ASN lookup via HackerTarget API
  • ASN metadata resolution via ipapi.is
  • WHOIS querying
  • RIPE Stat prefix enumeration

🔒 Security / Blocking

  • Generate nftables .nft rule files
  • Autosetup mode for Debian:
    • Installs all dependencies
    • Configures nftables
    • Places rules in /etc/nftables/ban4asn.nft
    • Enables persistent system service
    • Immediately applies drop rules

🧹 Unblocking

  • Removes the entire nftables ban4asn table cleanly
  • Supported in Python mode and CLI binary mode

🖥️ CrossPlatform Python Application

  • Works on:
    • Windows (CMD/PowerShell)
    • Linux (all major distros)
    • macOS
  • Debian gets special automation capabilities

🏗️ Optional Debian CLI Installer

  • Generates a binarylike command: ban4asn-cli
  • Allows full control without running the Python service
  • Supports ban, unblock, lookup, and rule deployment

📦 Installation

🔧 Requirements

  • Python 3.8+
  • pip install requests

🐧 Debian Installation with AutoInstaller

🐧 Debian Installation with AutoInstaller

You can install BAN4ASN using the included .sh installation script:

bash install_b4a.sh

You will be asked to select a source mirror:

Please select a mirror:
1. Alex's GIT (https://git.techotterdev.com/alex/BAN4ASN)
2. GitHub (https://github.com/alex/BAN4ASN)

Mirror behavior

  1. Alexs GIT mirror
  1. GitHub mirror
  • Uses GitHub repository
  • Same install behavior
  • Falls back easily if primary mirror is slow

CLI and system paths are set automatically.

Mirror Location's

Mirror Location
Alex's GIT Massapequa Park, NY, USA
GitHub Load Balanced (Location Based)
Alex's CDN (soon) Frankfurt, Germany

🧰 Usage Guide

Launch the Python Tool

python3 ban4asn.py

Lookup Example

1) Lookup IP/ASN
Enter 1.1.1.1
View WHOIS, ASN, prefixes, etc.

Create a nftables rule file

2) BAN
Select:
1) Generate .nft file

Debian AutoDeploy Mode

2) BAN
Select:
2) AutoInstall + Deploy nftables

Automatically:

  • Installs nftables
  • Creates rule file
  • Enables nftables system service
  • Applies block instantly

Unblock

3) Unblock

Removes full ban4asn nftables table.


🧪 CLI Binary Usage (Debian Only)

Once installed:

ban4asn-cli lookup 8.8.8.8
ban4asn-cli ban AS13335
ban4asn-cli auto-ban AS32934
ban4asn-cli unblock

📂 Project Structure

ban4asn.py                → Main crossplatform service
ban4asn.nft               → Generated rule file (only when banning)
setup_nftables.sh         → Auto-deploy script (Debian only)
ban4asn-cli               → Optional CLI binary-like wrapper
install_b4a.sh            → Debian installer script
README.md / README.txt    → Documentation

📝 License

This project is licensed under the MIT License.
Created by TechOtter.


❤️ Support / Contributions

Contributions are welcome!
Fork the project, submit PRs, or contact TechOtter for feature requests. Oh and yeah githubs AI banned me over this one :3 I got unbanned lol!