Last active
November 2, 2018 20:39
-
-
Save happyhater/a3a7e2fb21759b9680fb7d8a4e0a5769 to your computer and use it in GitHub Desktop.
This script will automatically detect people listed on DNSBL and ban them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use Irssi; | |
use Net::DNS; | |
use vars qw($VERSION %IRSSI); | |
$VERSION = "0.0.1"; | |
%IRSSI = ( | |
authors => "zmeu", | |
contact => "zmeu\@whitehat.ro", | |
name => "DNSBL autodetection.", | |
description => "This script will automatically detect people listed on DNSBL and ban them.". | |
license => "Public domain" | |
); | |
use constant { | |
DNSBL => "dnsbl.dronebl.org", | |
CACHETIME => 3600, | |
}; | |
my %cache; | |
sub resolve_host($) { | |
my $hostname = shift; | |
return $hostname if "$hostname." =~ (/^(\d{1,3}\.){4}$/); # yes, that sucks | |
my $res = Net::DNS::Resolver->new(); | |
my $q = $res->search($hostname, "A"); | |
return unless $q; | |
return map { $_->address } grep { $_->type eq "A" } $q->answer; | |
} | |
sub reverse_addr($) { | |
return join(".", reverse split(/\./, $_[0])); | |
} | |
sub isgot { | |
my ($server, $channel, $nickname, $address) = @_; | |
return unless ($nickname ne "" and $address =~ /.+@(.+)/); | |
Irssi::signal_continue($server, $channel, $nickname, $address); | |
my @hosts= split("\@", $address); | |
my $hostname = shift; | |
my $hostname = $hosts[1]; | |
my ($person, $channel) = split(/ /, $channel, 2); | |
my ($channelname) = split(/ /, $channel, 2); | |
my $witem = Irssi::window_item_find($channelname); | |
if (!$witem) { $witem = Irssi::active_win(); } | |
my $result = 0; | |
if (exists($cache{$hostname})) { | |
if (time >= $cache{$hostname}->[0]) { | |
delete $cache{$hostname}; | |
} else { | |
return $cache{$hostname}->[1]; | |
} | |
} | |
my ($ignore) = $hostname =~ m|([^./]+)\.org|; | |
my ($ignore2) = $hostname =~ m|([^./]+)\.ro|; | |
my ($ignore3) = $hostname =~ m|([^./]+)\.net|; | |
my ($ignore4) = $hostname =~ m|([^./]+)\.in|; | |
if (($ignore eq "undernet") or ($ignore2 eq "whitehat") or ($ignore3 eq "whitehat") or ($ignore4 eq "znc")) { | |
# we ignore them. | |
} else { | |
foreach my $addr (resolve_host($hostname)) { | |
if (grep /^127\.0\.0\.\d+$/, resolve_host(reverse_addr($addr).".".DNSBL)) { | |
$result = 1; | |
last; | |
} | |
} | |
} | |
$cache{$hostname} = [time+CACHETIME, $result]; | |
if($result eq "1") { | |
$witem->command("/kb ".$channelname." ".$nickname." Stop spamming."); | |
} | |
} | |
Irssi::signal_add("server event", \&isgot); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment