Tell me how to get an ISP from IP through PHP? Here, for example, for IP http://www.ip2location.com/demo/198.7.58.100, how to get the value of "LeaseWeb USA Inc."?
2 answers
You can start from the following script
<?php $sock = fsockopen('whois.arin.net', 43, $errno, $errstr); fputs ($sock, "198.7.58.100\r\n"); $text = ''; while (!feof($sock)) { $text = fgets ($sock, 128); $arr = explode(':', $text); if($arr[0] == 'OrgName') { echo $arr[1]; // LeaseWeb USA Inc. break; } }
- ARIN is an American registry and their whois responds only to requests for American IP. Total registries in the world are 5. And their api are mildly different - Mike
- @Mike, if ARIN cannot answer, it returns the referrer to the registry that can respond - just did not recursion. - cheops
- Well then, I would recommend starting with the download from iana.org of block allocation to registries (infa rarely changes, you should save it yourself). Whatever unnecessary requests do not fence. Immediately determine the registry and request from her. iana.org/assignments/ipv4-address-space/… - Mike
- @cheops ip2location.com/developers/php Why wise ? - E_p
- @E_p consider uploading several test 100MB databases (with relevance of 1 month, with the prospect of buying full databases and uploading really large volumes), is it better than sending a request to the official domain name registrar? And this is for the sake of one line? Forced to disagree. - cheops
|
And what you did not go to their section for developers http://www.ip2location.com/developers/php .
There and the library is for PHP.
<?php // Подключаем библиотеку require 'vendor/autoload.php'; $db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::FILE_IO); $records = $db->lookup('8.8.8.8', \IP2Location\Database::ALL); echo 'ISP Name: ' . $records['isp'] . PHP_EOL;
And the installation through composer:
composer.json:
{"require": {"ip2location / ip2location-php": "8. *"}}
> composer install
I do not like composer, here is the link to github. https://github.com/chrislim2888/IP2Location-PHP-Module
|