michaelcrowcroft/laravel-cloud-ip 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

michaelcrowcroft/laravel-cloud-ip

最新稳定版本:0.1.1

Composer 安装命令:

composer require michaelcrowcroft/laravel-cloud-ip

包简介

Track the IP ranges in use by cloud providers and determine if IP addresses are associated with them. Compatable with both IPv4 and IPv6.

README 文档

README

Track IP ranges in use by cloud providers and determine if IP addresses are associated with them. Compatable with both IPv4 and IPv6.

Cloud providers currently supported:

  • Amazon Web Services
  • Google Cloud Platform

Coming Soon:

  • Azure
  • Cloudflare

Installation

You can install the package via composer:

composer require michaelcrowcroft/laravel-cloud-ip

The package will automatically register itself.

While the package doesn't publish a migration file, you do need to run its migrations before using.

php artisan migrate

Now that you have migrated the cloud_ip table you can use the provided artisan command to populate the table with cloud provider's published IP ranges.

php artisan cloudip:get

Usage

Once the package is installed you can access information about the IP addresses cloud providers are using through CloudIP model. A list of th fields associated are below. This can be used like any other eloquent model.

A method is provided to select a record associated with an IP. We only select the first record, because one IP might be in multiple ranges that cloud providers use for difference services. Ultimately they will all come back to the same cloud provider though. This accepts an IP address as a long, hex, or in dot notation (as a string).

public function cloudIP()
{
    public static function HasIP($ip): self|null
    {
        $ip = IP::parse($ip);

        return CloudIP::where('first_ip', '<=', $ip->toLong())
            ->where('last_ip', '>=', $ip->toLong())
            ->first();
    }
}

This can be used as follows, returning the single CloudIP record that the IP is associated with if it is in fact associated with a cloud provider.

CloudIP::hasIP('3.2.34.0')->get();

Provided Fields

  • ip_prefix: A range of IPs in CIDR notation.
  • first_ip: The first IP in the range as a long.
  • last_ip: The last IP in the range as a long.
  • type: Whether an IP range is IPv4 or IPv6.
  • provider: The cloud provider the IP range is associated with.

Extra Tip

Cloud providers don't often change their IP addresses in use, but it can be worth setting up provided artisan command to run weekly in the scheduler to make sure your Cloud IP data is up to date.

// In your app/Console/Kernel.php file
protected function schedule(Schedule $schedule): void
{
    $schedule->command('cloudip:get')->weekly();
}

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-13