source: trunk/dnsbl/export-dnsbl@ 2

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

/trunk/dnsbl

Import work to date

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 1.8 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] || 'cidr';
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,'95.154.192.0/18');
27$dnsbl->export($ipref);
28
29##fixme - mode should pick actual output, not just export mode
30if ($mode eq 'cidr') {
31 foreach (sort ipcmp keys %iplist) {
32 print "$_\t$iplist{$_}\n";
33 }
34} else {
35 foreach (sort ipcmp keys %iplist) {
36#foreach (sort keys %iplist) {
37 my ($o1,$o2,$o3,$o4) = (/^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?$/);
38 print "+".(defined($o4) ? "$o4." : '').(defined($o3) ? "$o3." : '').(defined($o2) ? "$o2." : '').
39 "$o1.spamhosts.company.com:127.0.0.$iplist{$_}:900:::\n";
40 }
41}
42
43exit 0;
44
45# IP address comparison sub
46sub ipcmp {
47 my ($a1,$a2,$a3,$a4,$a5) = ($a =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
48 my ($b1,$b2,$b3,$b4,$b5) = ($b =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
49# le sigh. knew it wasn't going to be simple...
50 $b2 = -1 if $b2 && $b2 eq '*';
51 $b3 = -1 if $b3 && $b3 eq '*';
52 $b4 = -1 if $b4 && $b4 eq '*';
53 $b5 = 128 if !defined($b5);
54 $a2 = -1 if $a2 && $a2 eq '*';
55 $a3 = -1 if $a3 && $a3 eq '*';
56 $a4 = -1 if $a4 && $a4 eq '*';
57 $a5 = 128 if !defined($a5);
58 return 1 if $a1 > $b1;
59 return -1 if $a1 < $b1;
60 return 1 if $a2 > $b2;
61 return -1 if $a2 < $b2;
62 return 1 if $a3 > $b3;
63 return -1 if $a3 < $b3;
64 return 1 if $a4 > $b4;
65 return -1 if $a4 < $b4;
66 return 1 if $a5 > $b5;
67 return -1 if $a5 < $b5;
68 return 0;
69}
Note: See TracBrowser for help on using the repository browser.