Due to the historical reasons of the Internet, Apin is responsible for the overall planning of the entire network IP, as well as the IP allocation management of some African regions in North America, and accordingly, Whois.apin.net is the root server of IP whois, the standard IP whois query method is , first query the whois.apin.net for the region to which an IP belongs, and then query the WHOIS server for that IP for whois details.
The region currently responsible for IPV4
Whois.arin.net Americas North America
Whois.apnic.net Asia Pacific, including Australia
Whois.ripe.net Europe/Middle East (West Asia)/North Africa
Whois.lacnic.net Latin America and Caribbean area
IP queries for the African network are also whois.arin.net
The process of submitting a WHOIS query to a WHOIS server
Open a 43 port connection to the WHOIS server, and then send the domain name you want to query and a carriage return line. If you want to query multiple domain names, separate them with a space and read the results from the sokect. The last server will automatically disconnect.
Implemented in PHP
1. Verify IP (replace Ereg with Ip2long)
2. To whois.arin.net query, if there is no relevant information in the database, will give a referral server URL, the format is as follows
Referralserver:
Then, based on this information, continue to query
The code is as follows
whoisip.php
Include_once "lang.inc.php";
$IP = isset ($_get[' IP ")? $_get[' IP ']: ' Blank ';
if ( -1 = = Ip2long ($IP))
Die (Str_replace ('%ip% ', $IP, $Text [' ip_invalid ')];
echo Getwhois ($IP);
function Getwhois ($IP)
{
Global $Text;
$rootwhois = ' whois.arin.net ';
$buffer = Str_replace ('%SERVER% ', $rootwhois, $Text [' sock_connect ']);
$buffer 1 = readsocket ($rootwhois, $IP);
if ($buffer 1!== ")
{
$whois = Substrbytag ("referralserver:whois://", "\ n", $buffer 1);
Remove port number ": 43";
if (($pos =strpos ($whois, ":"))!== FALSE)
{
$whois = substr ($whois, 0, $pos);
}
if ($whois!== ")
{
$buffer. = Str_replace ('%SERVER% ', $whois, $Text [' sock_connect ']);
$buffer. = Readsocket ($whois, $IP);
}
Else
{
$buffer. = $buffer 1;
}
}
Return nl2br ($buffer);
}
function Substrbytag ($firstTag, $secondTag,& $longStr)
{
$firstPos = Strpos ($longStr, $firstTag);
$ret = ";
if ($firstPos!== FALSE)
{
$secondPos = Strpos ($longStr, $secondTag, $firstPos);
if ($secondPos!== FALSE)
{
$firstPos + = strlen ($FIRSTTAG);
$ret = substr ($longStr, $firstPos, $secondPos-$firstPos);
}
}
return $ret;
}
function Readsocket ($whois, $ip)
{
Global $Text;
$buffer = ";
if (! $sock = Fsockopen ($whois, $errNum, $ERRSTR, 20))
{
$buffer = Str_replace ('%SERVER% ', $whois, $Text [' sock_fail ']);
}
Else
{
Fputs ($sock, "$IP \ n");
$buffer = Fread ($sock, 8192);
while (!feof ($sock)) $buffer. =fgets ($sock, 8192);
Fclose ($sock);
}
return $buffer;
}
?>
Language files:
lang.inc.php
$Text = Array (
' Ip_invalid ' = ' I want to get a valid IP, but it's [%ip%]. ',
' Sock_connect ' = ' Ask%SERVER% ...
',
' Sock_fail ' = ' cannot connect to the host:%server% '
);
?>
Other well-known WHOIS servers
1.Tucows (whois.opensrs.net) Only one connection at a time
Dnsstuff is the one that queries it.
2.BulkRegister (whois.bulkregiter.net) Watch it temporarily seal the IP if a large number of connections are
3.Network Solutions (whois.networksolutions.com) can only be checked 1000 times a day.
4.Go Daddy (whois.godaddy.com)
5.whois.abuse.net
http://www.bkjia.com/PHPjc/313798.html www.bkjia.com true http://www.bkjia.com/PHPjc/313798.html techarticle due to the historical reasons of the Internet, Apin is responsible for the overall planning of the whole network IP and the IP allocation management in North America and some African regions, and accordingly, whois.apin.net is the IP whois ...