Created
August 21, 2020 17:08
-
-
Save helart/4502cacb5cbce557b5417864f0e6c3e0 to your computer and use it in GitHub Desktop.
Whois, как получить данные IP-адреса и домена в PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Информация о 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); | |
| // Информация о домене | |
| // С доменами сложнее, т.к. нужно отправлять TCP запрос на WHIOS-сервер в зависимости от зоны домена. Полный список серверов на https://www.whois365.com/en/listtld/. | |
| $server = 'whois.tcinet.ru'; | |
| $host = 'yandex.ru'; | |
| $socket = fsockopen($server, 43); | |
| if ($socket) { | |
| fputs($socket, $host); | |
| $text = ''; | |
| while (!feof($socket)) { | |
| $text .= fgets($socket, 128); | |
| } | |
| fclose($socket); | |
| echo $text; | |
| } | |
| /* | |
| Сервис для проверки 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment