1

I have a problem with php and whois.arin.net

$whois="whois.arin.net";
$ip="xx.xx.xx.xx";
$sk=fsockopen($whois, 43, $errno, $errstr, 30) or die('Connessione impossibile');
fputs ($sk, $ip."\r\n") or die('Request impossibile');
while (!feof($sk)) {
  $info.= fgets ($sk, 2048);
}

$i=explode("\n",$info);
foreach($i as $val){
  $descr=explode("\n",$val);
  echo $descr[0];
}

The error that appears is

ARIN WHOIS data and services are subject to the Terms of Use

Query terms are ambiguous. The query is assumed to be: n xx-xx-xx-xx

What is the problem?

Community
  • 1
  • 1
Luca
  • 43
  • 1
  • 7
  • Did you try `fputs($sk, 'n '.$ip."\r\n");` ? It seems to be saying that is the assumed command. – Devon Bessemer Jun 02 '14 at 13:43
  • If I modify, disappear the error query is ambiguous but remain the error ARIN WHOIS data and service are subject to Term of use – Luca Jun 02 '14 at 14:07

1 Answers1

4

A very simple PHP whois function that supports ARIN would look like this:

function whois($domain, $server) {

    // format input for the specific server
    if($server == 'whois.arin.net') {
        $domain = "n + $domain";
    }

    // connect and send whois query
    $connection = fsockopen($server, 43, $errno, $errstr, 30);
    $request = fputs($connection, $domain . "\r\n");

    if(!$connection OR !$request){
       return "Error $errno: $errstr.";
    }

    // get the whois data
    $data = '';
    while(!feof($connection)){
            $data .= fgets($connection);
    }

    fclose($connection);
    return trim($data);
}

Then you can call the function like so:

echo whois('8.8.8.8', 'whois.arin.net');
iglvzx
  • 498
  • 1
  • 8
  • 22
  • Can we add rwhois.hostwinds.com data also in this? – Mohan P Aug 16 '17 at 11:36
  • Just a note. This will not work on most shared hosting environments, as outgoing ports are usually shut down on a shared host these days because of security risks. Shared hosting scripts should use the Whois RWS API that returns Whois data as XML or JSON. More info on this at: http://whois.arin.net/ui/ – Epiphany Aug 09 '18 at 01:24