mattitjaab/bad-ip-blocker
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
418response.
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
mattitjaab/bad-ip-blocker 适用场景与选型建议
mattitjaab/bad-ip-blocker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 138 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mattitjaab/bad-ip-blocker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mattitjaab/bad-ip-blocker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 138
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-31