IPwhois query, domain name whois query-PHP source code

Source: Internet
Author: User
Tags tld
Ec (2); & lt; div & nbsp; classcontentbox & gt; & lt; divclass & quot; content_nav & quot; & gt; & lt; spanclass & quot; tt & quot; & gt; IP domain name WHOIS query & lt; span & gt; & lt; div & gt; & lt; divclasstoolitem & gt; & lt; br & gt; & lt; script ec (2); script


IP/Domain Name WHOIS Query








Require_once $ _ SERVER ['document _ root']. '/ad/mid. php ';
If ($ q2 <> ''){
If ($ isdomain ){
Echo'

';
Echo'

Query Result

';
Echo'

';
// Server List File
$ Config ['server _ list'] = "./whois/servers. lst ";
Whois ($ domain );
Echo'

';
Echo'

';
} Elseif ($ isip ){
Echo'

';
Echo'

Query Result

';
Echo'

';
$ Sourcecode = getsourcecode ("http://wq.apnic.net/apnic-bin/whois.pl? Searchtext = ". $ q );
// Echo $ sourcecode;
Preg_match ('/(

.*?)

/S', $ sourcecode, $ ipwhois );
$ Result = $ ipwhois [1];
$ Result = nl2br ($ result );
Echo $ result;
Echo'

';
Echo'

';
} Else {
Echo'

';
Echo'

Error!

';
Echo'

Error! Make sure that you entered either a domain name (not supported by a Chinese domain name at the moment) or an IP address. If you entered a phone number or something, we cannot find it!

';
Echo'

';
Echo'

';
}
} Else {
Echo'

';
Echo'

Tool description

';
Echo'

Enter an IP address or domain name, such as chaxun. la or xxx.

';
Echo'

';
Echo'

';
}
Function whois (){
Global $ domain;
If (! $ Server = get_server ()){
Die ("cannot query this type of domain name ");
}
$ Result = whois_request ($ server ['server'], $ domain );
If (! $ Result ){
Echo "unable to connect to the server ";
Die ();
}
$ Server ['info'] = trim ($ server ['info']);
If ($ server ['info']) {
$ He = strpos ($ result, $ server ['info']) + strlen ($ server ['info']);
$ Le = strpos ($ result, "", $ he );
$ Whois_server = trim (substr ($ result, $ he, $ le-$ he ));
$ Result2 = whois_request ($ whois_server, $ domain );
If ($ result2 ){
Echo nl2br ($ result. "The following information comes from:". $ whois_server. "". $ result2 );
} Else {
Echo nl2br ($ result );
}
} Else {
Echo nl2br ($ result );
}
}
/* Function whois (){
Global $ domain;
If (! $ Server = get_server ()){
Echo "this type of domain names cannot be queried ";
} Else {
$ Result = whois_request ($ server ['server'], $ domain );
If (! $ Result ){
Echo "unable to connect to the server ";
} Else {
Echo $ result;
}
}
}
*/
Function whois_request ($ server, $ query)
{
$ Data = "";
If (! $ Fp = @ fsockopen ($ server, 43 )){
Return false;
} Else {
Fputs ($ fp, $ query ."");
While (! Feof ($ fp )){
$ Data. = fread ($ fp, 1000 );
}
Fclose ($ fp );
}
// Return nl2br ($ data );
Return $ data;
}

Function get_server (){
Global $ config, $ domain;
$ Serverarray = file ($ config ['server _ list']);
$ I = 0;
Foreach ($ serverarray as $ key => $ val ){
If (substr ($ val, 0, 1 )! = "#"){
$ Server_p = explode ("|", $ val );
$ Server [$ I] ['tld '] = $ server_p [0];
$ Server [$ I] ['server'] = $ server_p [1];
$ Server [$ I] ['avail '] = $ server_p [2];
$ Server [$ I] ['infoserver'] = $ server_p [3];
$ Server [$ I] ['backserver'] = $ server_p [4];
$ Server [$ I] ['info'] = $ server_p [5];
}
$ I ++;
}

$ Domain_c = explode (".", $ domain );
$ Partnum = count ($ domain_c );
$ Last_part_1 = $ domain_c [$ partnum-1];
$ Last_part_2 = $ domain_c [$ partnum-2];

Foreach ($ server as $ key => $ val ){
If ($ val ['tld '] = $ last_part_2. ".". $ last_part_1 ){
Return $ val;
} Elseif ($ val ['tld '] = $ last_part_1 ){
Return $ val;
}
}
Return false;
}

$ Q = trim ($ _ GET ['q']);
$ Q2 = $ q;
If ($ q <> ''){
If ($ q = matchip ($ q2 )){
$ Isip = 1;
} Elseif ($ q = matchdomain ($ q2 )){
$ Domain = topdomain ($ q2 );
$ Isdomain = 1;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.