Zend - The PHP Company




Miscellaneous

Add Code


rWhois  

Type: code fragment
Added by: joeldg
Entered: 25/10/2002
Last modified: 31/10/2001
Rating: - (fewer than 3 votes)
Views: 4854
rWhois (see rwhois.net) in PHP. You can use this function to get geographic data back on on an IP, City/State/Zip this might come in handy if you are attempting to geo-target an IP by country, say, for an ad program.


<?php
################################################
# rWhois - Joel De Gan
# http://www.joihost.com, http://www.tenshimedia.com
#
# see http://www.rwhois.net/ for more information
#
# inputs: IP address
# outputs: array of rWhois info from first referral
# for other scripts see http://jabba.intercosmos.net
################################################
function rwhois($query){
    
$fp fsockopen ("rwhois.arin.net"4321$errno$errstr30);
    if (!
$fp) {
            
$ret[] = "$errstr ($errno)n";
    }else{
            
fputs ($fp"$queryrnrn");
        
$count=1;
            while (!
feof($fp) && $count 17) {
            
$back fgets ($fp,128);
            
$data explode(":",$back);
                
$ret[$data[1]] = $data[2];
            
$count++;
            }
//wend
          
fclose ($fp);
    }
//fi
   
return $ret;
}
//end function


print_r(rwhois("64.58.79.230")); //yahoo
?>


Usage Example


This outputs:
Array
(
    [003eff] => 00 rwhois.arin.net (by Network Solutions, Inc. V-1.5.7.2)
    [Class-Name] => network
    [Auth-Area] => 0.0.0.0/0
    [ID] => NET-64-58-76-0-1.0.0.0.0/0
    [Handle] => NET-64-58-76-0-1
    [Network-Name] => EC17-1-YAHOO1
    [IP-Network] => 64.58.76.0/22
    [IP-Network-Block] => 64.58.76.0 - 64.58.79.255
    [Org-Name] => Yahoo
    [City] => 701 First Avenue Sunnyvale
    [State] => CA
    [Postal-Code] => 94089
    [Country-Code] => US
    [Tech-Contact;I] => NA258-ARIN.0.0.0.0/0
    [Created] => 20201213050000000
    [Updated] => 19200303050000000


Rate This Script





Search



This Category All Categories