承接 mattitjaab/bad-ip-blocker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mattitjaab/bad-ip-blocker

最新稳定版本:v1.1.0

Composer 安装命令:

composer require mattitjaab/bad-ip-blocker

包简介

Block IPs based on a remote JSON file.

README 文档

README

Block incoming requests from known bad IP addresses using a centralized JSON feed.

This package fetches a list of bad IPs from a remote API hosted by Mattitja AB and caches them locally. Requests from matching IPs are immediately blocked with a 418 response.

Features

  • Automatically blocks known malicious IPs
  • Pulls IP list from a centralized JSON endpoint
  • Caches data locally to avoid repeated API calls
  • Designed to run globally across all routes

Installation

composer require mattitjaab/bad-ip-blocker

Usage

Register as global middleware in Laravel 12

Edit bootstrap/app.php:

use Mattitja\BadIpBlocker\Middleware\CheckBadIps;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        ...
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(CheckBadIps::class);
    })
    ->create();

This ensures the middleware runs globally on every incoming request.

How it works

  • On each request, the middleware checks if the client's IP exists in a cached JSON file.
  • If the cache is missing or older than one hour, it attempts to refresh from https://bad-ip.mattitja.cloud/api/json.
  • If the IP is found in the list, the request is blocked with a 418 response.

Cache location

Cached data is stored using Laravel's Cache facade (default: file driver):

storage/framework/cache/data/

To clear the cache and force a refresh:

php artisan cache:forget bad-ip-blocker

Or clear all cache:

php artisan cache:clear

Example response when blocked

HTTP/1.1 418 Blocked
Content-Type: text/plain

Blocked.

Maintained by Mattitja AB

This package is maintained by Mattitja AB and is intended for internal use across multiple projects.

License

MIT License © Mattitja AB

统计信息

  • 总下载量: 134
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-31