murilo-perosa / domain-tools
处理域名和DNS工具。
v1.0.8
2023-09-11 23:36 UTC
Requires
- php: >=7.3
- ext-intl: *
Requires (Dev)
- overtrue/phplint: ^2.3
- phpunit/phpunit: 9
- symfony/var-dumper: ^5.2
README
PHP - 简单库,用于处理基本的DNS情况。
- 名称转换;
- 名称净化;
- 名称验证;
- 检查名称SSL证书;
- 检查名称服务器;
- 获取名称部分(后缀、域名、子域名);
- 获取公共后缀列表;
- 获取和/或搜索DNS记录:'A', 'AAAA', 'CNAME', 'NS', 'SOA', 'MX', 'SRV', 'TXT', 'CAA', 'NAPTR', 'PTR', 'HINFO', 'A6'。
安装
composer require murilo-perosa/domain-tools
更新
composer update murilo-perosa/domain-tools
单元测试
使用PHPUnit运行单元测试
./vendor/bin/phpunit src/tests
代码风格检查
运行PHPLint
./vendor/bin/phplint ./
Name.php
用于处理域名和子域名名称的类。
变量
/** * Current name * @var string */ public $name; /** * Name Subdomain * @var string */ public $subdomain; /** * Name Domain * @var string */ public $domain; /** * Name sufix * @var string */ public $sufix; /** * Name is a subdomain * @var boolean */ public $is_subdomain; /** * List of Subdomains * @var array */ public $subdomains; /** * Parts of name * @var array */ public $parts; /** * Segments of name * @var array */ public $segments; /** * Name is valid * @var bool */ public $is_valid; /** * Domain records * @var Record */ public $records;
实例化类
use MuriloPerosa\DomainTools\Name; // instance the class $name = new Name('google.com');
更改状态函数
// convert name to UTF-8 $name->idnToUtf8(); // convert name to ASCII $name->idnToAscii(); // sanitize the name $name->sanitize(false); // sanitize the name and remove "www." $name->sanitize(true); // you can use them like this $name->idnToUtf8() ->sanitize();
通用函数
// get current name servers $name_servers = $name->getNameServers(); // check if name has ssl certificate $has_ssl = $name->hasSsl();
Sufix.php
用于处理名称后缀的类。
通用函数
use MuriloPerosa\DomainTools\Sufix; use MuriloPerosa\DomainTools\Name; // get the sufix list $list = Sufix::getSufixList(); // get name sufix $name = new Name('google.com'); $sufix = Sufix::getDnsSufix($name);
NameHelper.php
包含静态函数以处理情况的辅助类。
当你需要快速对名称进行操作时,必须使用该类。
通用函数
use MuriloPerosa\DomainTools\Helpers\NameHelper; // Sanitize name $name = NameHelper::sanitize('https://google.com', true); // 'https://google.com' => 'google.com' // Split name in parts $name = NameHelper::splitInParts('google.com'); // 'google.com' => ['google', 'com'] // Return name in segment $name = NameHelper::splitInSegments('google.com'); // 'google.com' => ['com', 'google.com'] // Validate name $is_valid = NameHelper::validate('google.com'); // true // Convert domain name from IDN to UTF-8 $name = NameHelper::idnToUtf8('xn--tst-qla.de'); // 'täst.de' // Convert domain name from IDN to ASCII $name = NameHelper::idnToASCII('täst.de'); // 'xn--tst-qla.de' // Check if name has SSL Certificate $has_ssl = NameHelper::hasSsl('google.com'); // true
Record.php
用于处理DNS记录的类。
变量
/** * Domain * @param string */ public $domain; /** * Allowed records to get * @param array */ private $allowed_records;
实例化类
use MuriloPerosa\DomainTools\Record; // instance the class $dns = new Record('google.com'); // OR use MuriloPerosa\DomainTools\Name; $name = new Name('google.com'); $dns = $name->records;
通用函数
// Return array with all records $records = $dns->getAll(); // Return array with all NS records $records = $dns->getNS(); // Return array with all A records $records = $dns->getA(); // Return array with all AAAA records $records = $dns->getAAAA(); // Return array with all CNAME records $records = $dns->getCNAME(); // Return array with all SOA records $records = $dns->getSOA(); // Return array with all MX records $records = $dns->getMX(); // Return array with all SRV records $records = $dns->getSRV(); // Return array with all TXT records $records = $dns->getTXT(); // Return array with all CAA records $records = $dns->getCAA(); // Not works on Windows (OS) // Return array with all NAPTR records $records = $dns->getNAPTR(); // Return array with all PTR records $records = $dns->getPTR(); // Return array with all HINFO records $records = $dns->getHINFO(); // Return array with all A6 records $records = $dns->getA6(); // Dinamic record search - returns a result array $records = $dns->search($type, $host); // to get records of all types or hosts you can use '*' $records = $dns->search('*', '*'); // you can use a string to specify wich type or host you want to search $records = $dns->search('A', 'php.net'); // you can use arrays to specify wich types or hosts you want to search $records = $dns->search(['A', 'MX'], ['php.net', 'blabla']); // You can use a mix of approaches // $records = $dns->search('*', '*'); // $records = $dns->search('*', 'php.net'); // $records = $dns->search('A', '*'); // $records = $dns->search(['A', 'MX'], ['php.net', 'blabla']); // $records = $dns->search('*', ['php.net', 'blabla']); // $records = $dns->search('A', ['php.net', 'blabla']); // $records = $dns->search(['A', 'MX'], '*'); // $records = $dns->search(['A', 'MX'], 'php.net'); // $records = $dns->search(['A', 'MX'], ['php.net', 'blabla']);
作者
Murilo Perosa <perosamurilo@gmail.com>