tourze/ip-collection-bundle

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

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/ip-collection-bundle

0.1.0 2025-05-05 08:25 UTC

This package is auto-updated.

Last update: 2025-11-01 19:17:41 UTC


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.