- Saved searches
- Use saved searches to filter your results more quickly
- License
- ip2whois/ip2whois-php
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Whois, как получить данные IP-адреса и домена в PHP
- Информация о IP
- Результат:
- Информация о домене
- Результат:
- Сервис для проверки IP и доменов
- Получение whois-данных домена на PHP
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
IP2WHOIS PHP SDK to help user to check WHOIS information for a particular domain.
License
ip2whois/ip2whois-php
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Please note that this GitHub project is no longer being maintained and has been migrated to a new repository. We recommend that you use the IP2Location.io PHP SDK going forward.
This PHP module enables user to easily implement the checking of WHOIS information for a particular domain into their solution using the API from https://www.ip2whois.com. It is a WHOIS lookup api that helps users to obtain domain information, WHOIS record, by using a domain name. The WHOIS API returns a comprehensive WHOIS data such as creation date, updated date, expiration date, domain age, the contact information of the registrant, mailing address, phone number, email address, nameservers the domain is using and much more. IP2WHOIS supports the query for 1113 TLDs and 634 ccTLDs.
This module requires API key to function. You may sign up for a free API key at https://www.ip2whois.com/register. It is available on the Packagist.
Lookup Domain Information
require_once __DIR__.'/vendor/autoload.php'; // Configures IP2WHOIS API key $config = new \IP2WHOIS\Configuration('YOUR_API_KEY'); $ip2whois = new \IP2WHOIS\Api($config); // Lookup domain information $ip2whois->lookup('example.com');
Convert Normal Text to Punycode
require_once __DIR__.'/vendor/autoload.php'; // Configures IP2WHOIS API key $config = new \IP2WHOIS\Configuration('YOUR_API_KEY'); $ip2whois = new \IP2WHOIS\Api($config); // Convert normal text to punycode $ip2whois->getPunycode('täst.de');
Convert Punycode to Normal Text
require_once __DIR__.'/vendor/autoload.php'; // Configures IP2WHOIS API key $config = new \IP2WHOIS\Configuration('YOUR_API_KEY'); $ip2whois = new \IP2WHOIS\Api($config); // Convert punycode to normal text $ip2whois->getNormalText('xn--tst-qla.de');
require_once __DIR__.'/vendor/autoload.php'; // Configures IP2WHOIS API key $config = new \IP2WHOIS\Configuration('YOUR_API_KEY'); $ip2whois = new \IP2WHOIS\Api($config); // Get domain name from URL $ip2whois->getDomainName('https://www.example.com/exe');
require_once __DIR__.'/vendor/autoload.php'; // Configures IP2WHOIS API key $config = new \IP2WHOIS\Configuration('YOUR_API_KEY'); $ip2whois = new \IP2WHOIS\Api($config); // Get domain extension (gTLD or ccTLD) from URL or domain name $ip2whois->getDomainExtension('example.com');
Parameter | Type | Description |
---|---|---|
domain | string | Domain name. |
domain_id | string | Domain name ID. |
status | string | Domain name status. |
create_date | string | Domain name creation date. |
update_date | string | Domain name updated date. |
expire_date | string | Domain name expiration date. |
domain_age | integer | Domain name age in day(s). |
whois_server | string | WHOIS server name. |
registrar.iana_id | string | Registrar IANA ID. |
registrar.name | string | Registrar name. |
registrar.url | string | Registrar URL. |
registrant.name | string | Registrant name. |
registrant.organization | string | Registrant organization. |
registrant.street_address | string | Registrant street address. |
registrant.city | string | Registrant city. |
registrant.region | string | Registrant region. |
registrant.zip_code | string | Registrant ZIP Code. |
registrant.country | string | Registrant country. |
registrant.phone | string | Registrant phone number. |
registrant.fax | string | Registrant fax number. |
registrant.email | string | Registrant email address. |
admin.name | string | Admin name. |
admin.organization | string | Admin organization. |
admin.street_address | string | Admin street address. |
admin.city | string | Admin city. |
admin.region | string | Admin region. |
admin.zip_code | string | Admin ZIP Code. |
admin.country | string | Admin country. |
admin.phone | string | Admin phone number. |
admin.fax | string | Admin fax number. |
admin.email | string | Admin email address. |
tech.name | string | Tech name. |
tech.organization | string | Tech organization. |
tech.street_address | string | Tech street address. |
tech.city | string | Tech city. |
tech.region | string | Tech region. |
tech.zip_code | string | Tech ZIP Code. |
tech.country | string | Tech country. |
tech.phone | string | Tech phone number. |
tech.fax | string | Tech fax number. |
tech.email | string | Tech email address. |
billing.name | string | Billing name. |
billing.organization | string | Billing organization. |
billing.street_address | string | Billing street address. |
billing.city | string | Billing city. |
billing.region | string | Billing region. |
billing.zip_code | string | Billing ZIP Code. |
billing.country | string | Billing country. |
billing.phone | string | Billing phone number. |
billing.fax | string | Billing fax number. |
billing.email | string | Billing email address. |
nameservers | array | Name servers |
< "domain": "greendot.com", "domain_id": "600750_DOMAIN_COM-VRSN", "status": "clientTransferProhibited http://www.icann.org/epp#clientTransferProhibited", "create_date": "1997-11-03T00:00:00Z", "update_date": "2021-10-29T01:13:27Z", "expire_date": "2023-11-02T05:00:00Z", "domain_age": 9319, "whois_server": "whois.corporatedomains.com", "registrar": < "iana_id": "299", "name": "CSC CORPORATE DOMAINS, INC.", "url": "www.cscprotectsbrands.com" >, "registrant": < "name": "Admin Role", "organization": "Green Dot Corporation", "street_address": "3465 E. Foothill Blvd", "city": "Pasadena", "region": "CA", "zip_code": "91107", "country": "US", "phone": "+1.8664120548", "fax": "+1.8664120548", "email": "adminrole@greendotcorp.com" >, "admin": < "name": "Admin Role", "organization": "Green Dot Corporation", "street_address": "3465 E. Foothill Blvd", "city": "Pasadena", "region": "CA", "zip_code": "91107", "country": "US", "phone": "+1.8664120548", "fax": "+1.8664120548", "email": "adminrole@greendotcorp.com" >, "tech": < "name": "Admin Role", "organization": "Green Dot Corporation", "street_address": "3465 E. Foothill Blvd", "city": "Pasadena", "region": "CA", "zip_code": "91107", "country": "US", "phone": "+1.8664120548", "fax": "+1.8664120548", "email": "adminrole@greendotcorp.com" >, "billing": < "name": "", "organization": "", "street_address": "", "city": "", "region": "", "zip_code": "", "country": "", "phone": "", "fax": "", "email": "" >, "nameservers": [ "dexter.ns.cloudflare.com", "aliza.ns.cloudflare.com" ] >
Whois, как получить данные IP-адреса и домена в PHP
Несколько примеров как в PHP получить информацию о домене и IP-адресе.
Информация о IP
Получить информацию об IP-адресе можно с помощью сервиса WHOIS REST API, отправив запрос на http://rest.db.ripe.net/search?query-string= xxx.xxx.xxx.xxx
Ответ будет в формате XML.
$ip = '213.180.193.1'; $xml = simplexml_load_string(file_get_contents('http://rest.db.ripe.net/search?query-string=' . $ip)); $array = json_decode(json_encode($xml), TRUE); $data = array(); foreach ($array['objects'] as $row) < foreach ($row as $row2) < foreach ($row2['attributes'] as $row3) < foreach ($row3 as $row4) < $data[$row4['@attributes']['name']][] = $row4['@attributes']['value']; >> > > print_r($data);
Результат:
Array( [inetnum] => Array( [0] => 213.180.193.0 - 213.180.193.255 ) [netname] => Array( [0] => YANDEX-213-180-193 ) [status] => Array( [0] => ASSIGNED PA ) [country] => Array( [0] => RU ) [descr] => Array( [0] => Yandex enterprise network [1] => Yandex enterprise network ) [admin-c] => Array( [0] => YNDX1-RIPE [1] => PGR777-RIPE ) [tech-c] => Array( [0] => YNDX1-RIPE [1] => EM3673-RIPE [2] => AUR2-RIPE ) [remarks] => Array( [0] => INFRA-AW [1] => trouble: ------------------------------------------------------ [2] => trouble: Points of contact for Yandex LLC Network Operations [3] => trouble: ------------------------------------------------------ [4] => trouble: Routing and peering issues: noc@yandex.net [5] => trouble: SPAM issues: abuse@yandex.ru [6] => trouble: Network security issues: abuse@yandex.ru [7] => trouble: Mail issues: postmaster@yandex.ru [8] => trouble: General information: info@yandex.ru [9] => trouble: ------------------------------------------------------ ) [mnt-by] => Array( [0] => YANDEX-MNT [1] => YANDEX-MNT [2] => YANDEX-MNT ) [created] => Array( [0] => 2011-08-30T09:34:57Z [1] => 2002-06-07T05:35:50Z [2] => 2012-02-09T15:59:56Z ) [last-modified] => Array( [0] => 2014-03-26T08:38:45Z [1] => 2018-08-03T07:15:46Z [2] => 2012-02-09T15:59:56Z ) [source] => Array( [0] => RIPE [1] => RIPE [2] => RIPE ) [role] => Array( [0] => Yandex LLC Network Operations ) [address] => Array( [0] => Yandex LLC [1] => 16, Leo Tolstoy St. [2] => 119021 [3] => Moscow [4] => Russian Federation ) [phone] => Array( [0] => +7 495 739 7000 ) [fax-no] => Array( [0] => +7 495 739 7070 ) [nic-hdl] => Array( [0] => YNDX1-RIPE ) [abuse-mailbox] => Array( [0] => abuse@yandex.ru ) [route] => Array( [0] => 213.180.193.0/24 ) [origin] => Array( [0] => AS13238 ) )
Информация о домене
С доменами сложнее, т.к. нужно отправлять TCP запрос (43-й порт) на WHIOS-сервер в зависимости от зоны домена, полный список whois-серверов.
Основные зоны
Зона | Сервер |
---|---|
.ru, .su, .рф | whois.tcinet.ru |
.com, .net | whois.verisign-grs.net |
.org | whois.pir.org |
$server = 'whois.tcinet.ru'; $host = 'yandex.ru'; $socket = fsockopen($server, 43); if ($socket) < fputs($socket, $host . PHP_EOL); $text = ''; while (!feof($socket)) < $text .= fgets($socket, 128); >fclose($socket); echo $text; >
Результат:
% By submitting a query to RIPN's Whois Service % you agree to abide by the following terms of use: % http://www.ripn.net/about/servpol.html#3.2 (in Russian) % http://www.ripn.net/about/en/servpol.html#3.2 (in English). domain: YANDEX.RU nserver: ns1.yandex.ru. 213.180.193.1, 2a02:6b8::1 nserver: ns2.yandex.ru. 93.158.134.1, 2a02:6b8:0:1::1 nserver: ns9.z5h64q92x9.net. state: REGISTERED, DELEGATED, VERIFIED org: YANDEX, LLC. registrar: RU-CENTER-RU admin-contact: https://www.nic.ru/whois created: 1997-09-23T09:45:07Z paid-till: 2019-09-30T21:00:00Z free-date: 2019-11-01 source: TCI Last updated on 2019-04-10T13:26:32Z
Сервис для проверки IP и доменов
Есть хороший API сервис «ip-api», возвращает информацию о домене, IP-адресе + геолакацию. Не требует регистрации и ключей, ограничение 150 запросов в минуту с одного IP-адреса, но не для коммерческого использования.
$host = 'yandex.ru'; $json = file_get_contents('http://ip-api.com/json/' . $host . '?lang=ru'); $array = json_decode($json, TRUE); print_r($array);
Array ( [as] => AS13238 YANDEX LLC [city] => Москва [country] => Россия [countryCode] => RU [isp] => Yandex enterprise network [lat] => 55.734 [lon] => 37.5883 [org] => Yandex LLC [query] => 5.255.255.80 [region] => MOW [regionName] => Москва [status] => success [timezone] => Europe/Moscow [zip] => )
Получение whois-данных домена на PHP
Скрипт проверяет и выводит дату истечения срока регистрации домена, а также количество дней до окончания срока регистрации домена (только .com/.net/.org).
Данный пример демонстрирует следующие аспекты программирования на PHP: работа с сокетами, регулярными выражениями, файловые операции, операции с датой и временем.
// Пример получения whois-данных домена // Источник: http://turenko.com/blog/2006/10/24/checking-whois-in-php/ // (c) Mikhail Turenko // доменное имя (com, net, org) $domain = "turenko.com"; // получаем whois-запись $resp = get_whois($domain); // извлекаем адрес whois-сервера preg_match("!^\s*Whois Server:\s+([\w\.]+)\b!im", $resp, $matches); $server = $matches[1]; // извлекаем дату истечения срока домена preg_match("!^\s*Expiration Date:\s+([\w\-]+)\b!im", $resp, $matches); $expiry = $matches[1]; // вычисляем количество дней до окончания срока $exptime = strtotime($expiry); $expdays = round(($exptime - time()) / 84600); $expiry = date("d/m/Y", $exptime); print "Domain: $domain\n"; print "Whois server: $server\n"; print "Expires: $expiry\n"; print "Days left: $expdays\n"; function get_whois($domain, $server="whois.verisign-grs.com") < if (trim($domain) <>"") < $domain = trim($domain); $fp = fsockopen($server, 43, $errno, $errstr, 30); if (!$fp) $response = "$errstr ($errno)"; else< $response = ""; fputs($fp, "$domain\r\n"); while (!feof($fp)) $response .= fread($fp,128); fclose ($fp); >> return $response; >