jinomial / laravel-dns
Laravel 的 DNS 服务
v2.0.1
2023-08-31 00:28 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.7
- illuminate/contracts: ^10.18
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.22
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.6
- pestphp/pest: ^2.13
- pestphp/pest-plugin-laravel: ^2.1
- pestphp/pest-plugin-mock: ^2.0
- spatie/laravel-ray: ^1.32
- vimeo/psalm: ^5.14
This package is auto-updated.
Last update: 2024-09-30 01:34:56 UTC
README
Laravel 的 DNS 服务。使用它包含的 DNS over HTTPS (DoH) 驱动程序或创建您自己的自定义驱动程序。
安装
您可以通过 composer 安装此包
composer require jinomial/laravel-dns
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Jinomial\LaravelDns\DnsServiceProvider" --tag="laravel-dns-config"
这是发布配置文件的内容
return [ /* |-------------------------------------------------------------------------- | Default DNS |-------------------------------------------------------------------------- | | This option controls the default DNS socket that is used by the DNS | service. Alternative DNS sockets may be setup and used as needed; | however, this socket will be used by default. | */ 'default' => env('DNS_SOCKET', 'doh'), /* |-------------------------------------------------------------------------- | DNS Socket Configurations |-------------------------------------------------------------------------- | | Here you may configure all of the DNS sockets used by your application | plus their respective settings. Several examples have been configured for | you and you are free to add your own as your application requires. | | Supported: "doh", "system", | */ 'sockets' => [ 'doh' => [ 'driver' => 'doh', 'endpoint' => env('DOH_ENDPOINT', 'https://cloudflare-dns.com/dns-query'), 'guzzle' => [ 'connect_timeout' => 0, 'timeout' => 0, 'verify' => false, ] ], 'system' => [ 'driver' => 'system', ], ], ];
用法
响应取决于所使用的驱动程序。
doh 驱动程序响应
doh 驱动程序使用 Cloudflare 的 DNS over HTTPs 并以 JSON 格式进行查询。
有关响应格式的详细信息,请参阅 响应文档。
$response = Dns::query('ipv6.localhost.jinomial.com', 'aaaa'); print_r($response); // Array // ( // [Status] => 0 // [TC] => // [RD] => 1 // [RA] => 1 // [AD] => // [CD] => // [Question] => Array // ( // [0] => Array // ( // [name] => ipv6.localhost.jinomial.com // [type] => 28 // ) // // ) // // [Answer] => Array // ( // [0] => Array // ( // [name] => ipv6.localhost.jinomial.com // [type] => 28 // [TTL] => 298 // [data] => ::1 // ) // // ) // // )
系统驱动程序响应
系统 驱动程序使用 PHP 的 dns_get_record
方法进行查询。
有关响应格式的详细信息,请参阅 dns_get_record 文档。
$response = Dns::query('ipv6.localhost.jinomial.com', 'aaaa'); print_r($response); // Array // ( // [0] => Array // ( // [host] => ipv6.localhost.jinomial.com // [class] => IN // [ttl] => 377 // [type] => AAAA // [ipv6] => ::1 // ) // // )
批量查询
可以同时执行多个查询。
$response = Dns::query([ [ 'name' => 'ipv6.localhost.jinomial.com', 'type' => 'AAAA', ], [ 'name' => 'ipv4.localhost.jinomial.com', 'type' => 'A', ], ]);
doh 驱动程序支持异步查询。
$promises = Dns::query($queries, null, ['async' => true]); $response = Dns::unwrap($promises);
测试
运行所有测试
composer test
测试套件分为 "单元" 和 "集成"。运行每个套件
composer test-unit composer test-integration
测试被分组到以下组
- 网络
- 驱动程序
- doh
- 管理器
- 外观
- 命令
运行组测试
composer test -- --include=manager,facades
网络测试会进行远程调用,可能需要时间或失败。请排除它们
composer test-unit -- --exclude=network
变更日志
请参阅 变更日志 了解最近的变化。
贡献
请参阅 贡献指南 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。