source: trunk/dnsbl/export-dnsbl@ 6

Last change on this file since 6 was 6, checked in by Kris Deugau, 15 years ago

/trunk/dnsbl

Tweak and polish a few docu-comments

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 2.0 KB
Line 
1#!/usr/bin/perl
2# Export DNSBL data
3# 2009/05/26 kdeugau@deepnet.cx
4# need to stub it out so it can use a module to actually write zone
5# data for different NS software
6# completed 2008/08/14
7
8use strict;
9use warnings;
10use DBI;
11
12use DNSBL;
13
14my $dnsbl = new DNSBL;
15
16$dnsbl->connect;
17
18my %iplist;
19my $ipref = \%iplist;
20
21my $mode = $ARGV[0] || 'tiny';
22
23#$dnsbl->export($ipref,$mode,1,'65.60/18');
24#$dnsbl->export($ipref,$mode,1,'67.136.0.0/14');
25#$dnsbl->export($ipref,$mode,1,'83.76/15');
26#$dnsbl->export($ipref,$mode,1,'76.73.0.0/17');
27#$dnsbl->export($ipref,$mode,1,'174.36.0.0/15');
28$dnsbl->export($ipref,$mode);
29
30##fixme - mode should pick actual output, not just export mode
31if ($mode eq 'cidr') {
32 # more or less raw CIDR block-and-IP info. rbldnsd format for convenience.
33 foreach (sort ipcmp keys %iplist) {
34 print "$_:127.0.0.$iplist{$_}:".
35 ($iplist{$_} & 2 ? '$ relayed a reported spam' : 'Netblock listed on one or more criteria')."\n";
36 }
37} else {
38 foreach (sort ipcmp keys %iplist) {
39 my ($o1,$o2,$o3,$o4) = (/^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?$/);
40 print "+".(defined($o4) ? "$o4." : '').(defined($o3) ? "$o3." : '').(defined($o2) ? "$o2." : '').
41 "$o1.spamhosts.company.com:127.0.0.$iplist{$_}:900:::\n";
42 }
43}
44
45exit 0;
46
47# IP address comparison sub
48sub ipcmp {
49 my ($a1,$a2,$a3,$a4,$a5) = ($a =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
50 my ($b1,$b2,$b3,$b4,$b5) = ($b =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
51# le sigh. knew it wasn't going to be simple...
52 $b2 = -1 if $b2 && $b2 eq '*';
53 $b3 = -1 if $b3 && $b3 eq '*';
54 $b4 = -1 if $b4 && $b4 eq '*';
55 $b5 = 128 if !defined($b5);
56 $a2 = -1 if $a2 && $a2 eq '*';
57 $a3 = -1 if $a3 && $a3 eq '*';
58 $a4 = -1 if $a4 && $a4 eq '*';
59 $a5 = 128 if !defined($a5);
60 return 1 if $a1 > $b1;
61 return -1 if $a1 < $b1;
62 return 1 if $a2 > $b2;
63 return -1 if $a2 < $b2;
64 return 1 if $a3 > $b3;
65 return -1 if $a3 < $b3;
66 return 1 if $a4 > $b4;
67 return -1 if $a4 < $b4;
68 return 1 if $a5 > $b5;
69 return -1 if $a5 < $b5;
70 return 0;
71}
Note: See TracBrowser for help on using the repository browser.