Due to historical Internet reasons, apin is responsible for the overall plan of all network IP addresses and IP address allocation and governance in parts of Africa in North America. correspondingly, whois.apin.net is the rootserver of IPwhois, the scale IPwhois query method is: first, to wh due to historical Internet reasons, apin is responsible for the overall plan of all network IP addresses and IP address allocation and management in parts of Africa in North America. correspondingly, whois.apin.net is the root server of IP whois. the IP whois query method of the scale is to first query whois.apin.net which region an IP belongs, then, query the whois information of the IP address from the whois server in the region.
IPV4 region
Whois.arin.net America North America
Whois.apnic.net Asia Pacific includes Asia and Australia
Whois.ripe.net Europe/Middle East (Western Asia)/North Africa
Whois.lacnic.net latex and the Caribbean
IP address query for African networks is also in whois.arin.net.
The process of submitting a whois query to a whois server
Open a connection to Port 43 of the whois server, and then send the domain name to be queried and a line break with a carriage return. If you want to query multiple domain names, use spaces to exit and then read the results from sokect. The server will be disconnected.
PHP implementation
1. verify the IP address (replace ereg with ip2long)
2. query whois.arin.net. if there is no relevant information in the database, a URL of the Referral Server will be provided. the pattern is as follows:
ReferralServer:
Then, based on this information, the query continues.
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 ']);
$ Buffer1 = ReadSocket ($ rootwhois, $ IP );
If ($ buffer1! = '')
{
$ Whois = SubStrByTag ('referralserver: whois: // ',' \ n', $ buffer1 );
// 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. = $ buffer1;
}
}
Return nl2br ($ buffer );
}
Function SubStrByTag ($ firstTag, $ secondTag, & $ longStr)
{
$ FirstPos = strpos ($ longStr, $ firstTag );
$ Ret = '';
If ($ firstPos! = FALSE)
{
$ SecondPos = strpos ($ longStr, $ secondTag, $ firstPos );