定制 tourze/ip-collection-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tourze/ip-collection-bundle

最新稳定版本:0.1.0

Composer 安装命令:

composer require tourze/ip-collection-bundle

包简介

IP地址收集和标记管理工具,支持多种IP来源同步

README 文档

README

Latest Version PHP Version License Total Downloads Code Coverage

English | 中文

A Symfony Bundle for collecting and managing IP address information from various sources including AWS, cloud providers, and BT trackers.

Features

  • Synchronize various public IP address lists
  • Collect BT Tracker addresses
  • Synchronize AWS IP address ranges
  • IP address tagging and management
  • Automated synchronization with cron jobs

Installation

Requirements

This bundle requires the following dependencies:

  • PHP 8.1 or higher
  • Symfony 7.3+
  • Doctrine ORM 3.0+
  • Additional packages:
    • league/uri: URI manipulation library
    • nesbot/carbon: Date manipulation library
    • yiisoft/json: JSON encoding/decoding
    • tourze/doctrine-upsert-bundle: Database upsert operations
    • tourze/symfony-lock-command-bundle: Command locking
    • tourze/symfony-cron-job-bundle: Cron job scheduling

Install via Composer

composer require tourze/ip-collection-bundle

Configuration

Add the bundle to your config/bundles.php:

return [
    // ...
    IpCollectionBundle\IpCollectionBundle::class => ['all' => true],
];

Usage

Commands

The Bundle provides the following console commands:

  • game-boost:sync-cidr - Synchronize IP address lists from various cloud providers and sources
  • ip-collection:sync-aws-ip-range - Synchronize AWS IP address ranges
  • bt:sync-public-tracker - Collect public BT Tracker addresses

All commands are configured with automatic cron scheduling and can also be executed manually.

Manual Execution

# Synchronize AWS IP ranges (runs every 6 hours)
php bin/console ip-collection:sync-aws-ip-range

# Sync CIDR lists from various cloud providers (runs every 6 hours)
php bin/console game-boost:sync-cidr

# Collect BT tracker addresses (runs daily at 6:33 AM)
php bin/console bt:sync-public-tracker

Entities

The Bundle includes the following entities:

  • IpTag - Stores IP address tag information
  • BtTracker - Stores BT Tracker information

Advanced Usage

Customizing IP Sources

You can extend the SyncCidrListCommand class to add your own IP data sources:

class CustomSyncCommand extends SyncCidrListCommand
{
    protected function getProviders(): \Traversable
    {
        // Add your custom providers here
        yield 'custom-source' => [
            'https://example.com/ip-list.txt',
        ];
        
        // Include default providers
        yield from parent::getProviders();
    }
}

Working with IP Tags

use IpCollectionBundle\Entity\IpTag;
use Doctrine\ORM\EntityManagerInterface;

// Find IPs by tag
$repository = $entityManager->getRepository(IpTag::class);
$awsIps = $repository->findBy(['tag' => 'aws-ipv4']);
$chinaIps = $repository->findBy(['tag' => 'geoip2-cn']);
$aliyunIps = $repository->findBy(['tag' => 'aliyun']);

// Check if an IP belongs to a specific provider
$isAwsIp = $repository->findOneBy([
    'address' => '203.0.113.0/24',
    'tag' => 'aws-ipv4'
]) !== null;

Working with BT Trackers

use IpCollectionBundle\Entity\BtTracker;

// Get all active trackers
$trackerRepository = $entityManager->getRepository(BtTracker::class);
$trackers = $trackerRepository->findAll();

// Filter by protocol
$udpTrackers = array_filter($trackers, fn(BtTracker $tracker) => 
    str_starts_with($tracker->getUrl(), 'udp://')
);

Testing

Run the following command in the project root directory to execute tests:

vendor/bin/phpunit packages/ip-collection-bundle/tests

Contributing

Please see CONTRIBUTING.md for details on how to contribute to this project.

Changelog

Please see CHANGELOG.md for information about recent changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-03