added support form Referral Whois (RFC 1714/2167)

This commit is contained in:
sparc 2005-08-26 08:11:15 +00:00
parent 547d6f560c
commit 649190efa9
9 changed files with 148 additions and 48 deletions

View file

@ -1,5 +1,8 @@
2005/08/26 David Saez <david@ols.es>
- code cleanup and formatting
- code cleanup and formatting
- added support form Referral Whois (rwhois)
as per RFC 1714/2167, support is limited, non
recursive and only for ARIN ip space
2005/08/19 David Saez <david@ols.es>
- fixed some bad includes

View file

@ -74,8 +74,8 @@ the following subkeys:
handle -> network/AS handle
source -> who gives this information
owner,admin,tech,zone,billing,abuse
-----------------------------------
owner,admin,tech,zone,billing,abuse,customer
--------------------------------------------
All of these possible keys hold information about the different
contacts of the domain or ip address. They all could have the
@ -101,6 +101,9 @@ the following subkeys:
changed -> last change date
source -> who provided that information
remarks -> remarks
inetnum -> only for ip whois for customer
object, ip space assigned to
customer
Not all handlers fill values in each of the keys defined by the
Common Object Model as not all registries return the same amount

View file

@ -16,9 +16,11 @@ handler exists, the special handler will parse the output and make
additional elements available in the response. The keys of these
additional elements are described in the file HANDLERS.
It also supports ip whois queries which are very useful to trace
SPAM. You just only need to pass the doted quad ip address instead
of the domain name.
It also supports ip/AS whois queries which are very useful to trace
SPAM. You just only need to pass the doted quad ip address or the
AS (Autonomus System) handle instead of the domain name. Limited,
non-recursive support for Referral Whois (RFC 1714/2167) is also
provided.
Installation
------------

View file

@ -92,13 +92,6 @@ class WhoisClient {
}
else
{
// If the '.cx' whois server is broken, return an error now (saves attempting and timing out)
/*
if($this->HACKS["cx_is_broken"] && $this->Query["tld"] == "cx") {
$this->Query["errstr"][] = ".cx doesn't work. Turn off HACKS[\"cx_is_broken\"] if ".$this->Query["server"]." finally got fixed.";
return("");
}
*/
// Connect to whois server, or return if failed
$ptr = $this->Connect();
@ -222,21 +215,40 @@ class WhoisClient {
*
* Returns a socket connection pointer on success, or -1 on failure.
*/
function Connect () {
function Connect ($server = '') {
if ($server == '')
$server = $this->Query['server'];
// Fail if server not set
if(!isSet($this->Query['server']))
if($server == '')
return(-1);
// Get rid of protocol and/or get port
$port = $this->PORT;
$pos = strpos($server,'://');
if ($pos !== false)
$server = substr($server, $pos+3);
$pos = strpos($server,':');
if ($pos !== false)
{
$port = substr($server,$pos+1);
$server = substr($server,0,$pos);
}
// Enter connection attempt loop
$server = $this->Query['server'];
$retry = 0;
while($retry <= $this->RETRY) {
// Set query status
$this->Query['status'] = 'ready';
// Connect to whois port
$ptr = @fsockopen($server, $this->PORT);
$ptr = @fsockopen($server, $port);
if($ptr > 0) {
$this->Query['status']='ok';
return($ptr);

View file

@ -64,7 +64,8 @@ class arin_handler
"abuse.name" => "OrgAbuseName:",
"abuse.handle" => "OrgAbuseHandle:",
"abuse.phone" => "OrgAbusePhone:",
"abuse.email" => "OrgAbuseEmail:"
"abuse.email" => "OrgAbuseEmail:",
'rwhois' => 'ReferralServer:'
);
return generic_parser_b($data_str, $items, 'ymd', false);

View file

@ -83,12 +83,12 @@ class ip_handler extends WhoisClient
$orgname = trim($rawdata[1]);
while (list($string, $whois) = each($this->REGISTRARS))
if (strstr($orgname, $string) != '')
{
$this->Query['server'] = $whois;
$result['regyinfo']['registrar'] = $string;
break;
}
if (strstr($orgname, $string) != '')
{
$this->Query['server'] = $whois;
$result['regyinfo']['registrar'] = $string;
break;
}
switch ($this->Query['server'])
{
@ -198,6 +198,23 @@ class ip_handler extends WhoisClient
$result['regrinfo']['network']['inetnum'] = $this->cidr_conv($result['regrinfo']['network']['cdir']);
}
//Check if Referral rwhois server has been reported
if (isset($result['regrinfo']['rwhois']))
{
$this->Query['server'] = $result['regrinfo']['rwhois'];
unset($result['regrinfo']['rwhois']);
//If so, get customer data from rwhois
$this->Query['handler'] = 'rwhois';
$this->Query['file'] = 'whois.rwhois.php';
$rwdata = $this->GetData($query);
$rwres = $this->Process($rwdata);
$result['regrinfo']['customer'] = $rwres;
$result['regyinfo']['rwhois'] = $this->Query['server'];
}
return $result;
}

View file

@ -125,31 +125,33 @@ $r='';
$disok=true;
while (list($key,$val)=each($rawdata))
{ if (trim($val)!='')
{
{
if (trim($val)!='')
{
if (($val[0]=='%' || $val[0]=='#') && $disok)
{ $r['disclaimer'][]=trim(substr($val,1));
$disok=true;
continue;
}
$disok=false;
reset($items);
while (list($field, $match)=each($items))
{
$pos=strpos($val,$match);
if ($pos!==false)
{
$var="\$r".getvarname($field);
$itm=trim(substr($val,$pos+strlen($match)));
if ($itm!='')
eval($var."=\"".$itm."\";");
break;
}
}
}
}
$r['disclaimer'][]=trim(substr($val,1));
$disok=true;
continue;
}
$disok=false;
reset($items);
while (list($field, $match)=each($items))
{
$pos=strpos($val,$match);
if ($pos!==false)
{
$var = "\$r".getvarname($field);
$itm = trim(substr($val,$pos+strlen($match)));
if ($itm!='')
eval($var."=\"".$itm."\";");
break;
}
}
}
}
if (empty($r))
{
@ -158,7 +160,8 @@ if (empty($r))
else
{
if ($hasreg) $r['registered'] = 'yes';
$r=format_dates($r,$dateformat);
$r = format_dates($r, $dateformat);
}
return $r;

56
src/whois.rwhois.php Executable file
View file

@ -0,0 +1,56 @@
<?php
/*
Whois.php PHP classes to conduct whois queries
Copyright (C)1999,2005 easyDNS Technologies Inc. & Mark Jeftovic
Maintained by David Saez (david@ols.es)
For the most recent version of this package visit:
http://phpwhois.sourceforge.net
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
if (!defined('__RWHOIS_HANDLER__'))
define('__RWHOIS_HANDLER__', 1);
require_once('whois.parser.php');
class rwhois_handler
{
function parse($data_str, $query)
{
$items = array(
'name' => 'network:Organization-Name:',
'address.city' => 'network:Organization-City:',
'address.pcode' => 'network:Organization-Zip:',
'address.country' => 'network:Organization-Country:',
'inetnum' => 'network:IP-Network-Block:',
'handle' => 'network:Network-Name:',
'created' => 'network:Created:',
'changed' => 'network:Updated:'
);
$res = generic_parser_b($data_str['rawdata'], $items, 'Ymd', false);
unset($res['disclaimer']);
return ($res);
}
}
?>

View file

@ -62,6 +62,7 @@ biz neulevel.biz
afrinic 66.18.70.6
apnic 218.165.121.114
arin 207.217.120.54
arain+rwhois 70.84.47.210
bripw 200.165.206.74
krnic 210.178.148.129
lacnic 200.44.33.31
@ -70,3 +71,5 @@ ripe 62.97.102.115
// ASN
arin AS220