<html><head><title>spfilter bulk lookup</title>
</head><body><form action="/lookup.php" method="POST">
<table Xbgcolor="#F4F4F4" border="0" cellspacing="2" cellpadding="4"><tr>
<?php
#$dbfile = 'lookup.gdbm';
$dbfile = '';
$limit = 256;
if($_POST["addr"])
{
if(!$dbfile) { $spfilter = 'disabled'; }
elseif($spfilter) { $spfilter = 'checked'; }
if($reverse) { $reverse = 'checked'; }
if($verbose) { $verbose = 'checked'; }
if($textonly) { $textonly = 'checked'; }
}
else # set defaults
{
if($dbfile) { $spfilter = 'checked'; }
else { $spfilter = 'disabled'; }
$reverse = 'checked';
$verbose = '';
$textonly = 'checked';
}
?>
<td valign="top" nowrap>[<a href="/">^</a>]
<font color="red" size="+1"><b>spfilter bulk lookup</b></font>
<br>[<a href="javascript:history.back();"><< BACK</a>]
<div align="right">
SPEWS2 <input disabled <?=$spfilter?> type="checkbox" name="SPEWS2" value="1"><br>
SPAMSITE <input disabled <?=$spfilter?> type="checkbox" name="SPAMSITE" value="1"><br>
PERMBLOCK <input disabled <?=$spfilter?> type="checkbox" name="PERMBLOCK" value="1"><br>
<!-- PDL <input disabled <?=$spfilter?> type="checkbox" name="PDL" value="1"><br> -->
REVERSE <input <?=$reverse?> type="checkbox" name="reverse" value="1"></div>
</td><td align="center" valign="top"><textarea name="addr" cols="18" rows="9">
<?
$input = array();
$unique = array();
$lookup = array();
if($_POST["addr"])
{
$input = explode("\n", $_POST["addr"]);
$unique = array_unique($input);
$count = 0;
foreach($unique as $addr)
{
list($a,$b,$c,$d,$junk) = preg_split("/[^0-9]+/", $addr,5);
if($a >0 && $a < 255)
{
if(!$b || $b == '*') { $b = 0; }
if(!$c || $c == '*') { $c = 0; }
if(!$d || $d == '*')
{
echo "$a.$b.$c.0\n";
for($d=0; $d<256; $d++)
{
$addr = "$a.$b.$c.$d";
$lookup[$addr] = $addr;
}
}
else
{
$addr = "$a.$b.$c.$d";
$lookup[$addr] = $addr;
echo $addr."\n";
}
if($count++ > $limit) { break; }
}
}
reset($unique);
reset($lookup);
}
else # make up some default
{
echo "127.0.0.2\n";
echo $_SERVER["REMOTE_ADDR"]."\n";
if($_SERVER["HTTP_X_FORWARDED_FOR"]) { echo $_SERVER["HTTP_X_FORWARDED_FOR"]."\n"; }
if($_COOKIE["q"]) { echo $_COOKIE["q"]."\n"; }
}
?>
</textarea></td><td align="left" valign="bottom">
<input <?=$spfilter?> type="checkbox" name="spfilter" value="1">SPFilter<br>
<input <?=$verbose?> type="checkbox" name="verbose" value="1">Verbose<br>
<input <?=$textonly?> type="checkbox" name="textonly" value="1" disabled>Text Only<br>
Stepping <select name="step" disabled><option selected>1<option>8<option>32</select>
<p><input type="submit" name="" value="Submit Query">
</td><td width="*" valign="top" nowrap>
<div align="center"><a href="http://sourceforge.net/"><img src="http://sourceforge.net/sflogo.php?group_id=49927" width="88" height="31" border="0" alt="SourceForge"></a></div>
<br><small>
sample application for [<a href="http://spfilter.openrbl.org/">spfilter</a>]<br>
DB built from DEFAULT sources<br>
enter 3 octets for whole block (/24)<br>
input/output limited to <?=$limit?> lines<br>
manual usage only - no scripting<br>
[<a href="lookup.phps">php source</a>] [<a href="./">form reset</a>]
</small></td></tr></table></form>
<?
if(!$dbfile)
{
echo '<blockquote><div style="width:580; text-align:center; background:yellow; border-style:solid; border-width:2; border-color:red;">';
echo '<font color="red"><b>*** bulk-db not available due to limited quota and cpu at sourceforge.net ***</b></font><br>';
echo 'News: thanks to an unnamed sponsor bulk-lookups will be available later this year.';
# echo 'requirments: shell/web/php, cron/rsync/db4, 500mb quota, 265mb ram, scsi or tmpfs<br>';
# echo 'updated <a href="http://mirror.bliab.com/database/">databases</a> distributed only to a few trusted servers, traffic about 2gb/month<br>';
# echo 'serious sponsors welcome - please contact <a href="http://openrbl.org/feedback">webmaster(at)openrbl.org</a> with details';
echo '</div></blockquote>';
}
if($_POST["addr"])
{
echo '<plaintext>';
$count = dbLookup($dbfile,$lookup);
if(count($lookup)) { echo "\n",count($lookup),' lookups, ',$count,' matches found',"\n"; }
}
#################################
function dbLookup($dbfile,$lookup)
{ global $spfilter,$google,$reverse,$limit,$verbose;
if($dbfile)
{
$dba = @dba_open($dbfile, 'r', 'gdbm');
if(!$dba) { echo "failed dba_open($dbfile): please try again later"; exit(); }
}
$count = 0;
$queries = 0;
reset($lookup);
foreach($lookup as $addr)
{
if($reverse)
{
if($rdns=gethostbyaddr($addr))
{
if($rdns != $addr) { echo $addr,' ',$rdns,"\n"; flush(); }
elseif($verbose) { echo $addr,' unresolved',"\n"; }
}
elseif($verbose) { echo $addr,' dnserror',"\n"; }
}
if($dba && $spfilter)
{
if($text=dbRecord($dba,$addr))
{
echo $addr,' ',$text."\n";
if($count++ > $limit) { break; }
flush();
}
elseif($verbose) { echo $addr,' unlisted',"\n"; }
}
if($queries++ > ($limit*2)) { break; }
}
if($dba) { dba_close($dba); }
return($count);
}
function dbRecord($dba, $addr)
{
$text = '';
if($val=dba_fetch($addr, $dba)) { $text = $val; }
list($a,$b,$c,$d) = explode('.',$addr);
if($val=dba_fetch("$a.$b.$c", $dba))
{
if($text) { $text .= '; '; }
$text .= $val;
}
if($val=dba_fetch("$a.$b", $dba))
{
if($text) { $text .= '; '; }
$text .= $val;
}
return($text);
}
?>