X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fshow%2Fbadip.pl;h=832c98cdc470027c7194573dcf40655034b3638d;hb=d46e81d715d7d2050c924a608c31cf8ab5143e3f;hp=475abde165e2856454874dcc5147be223868a916;hpb=ceb2daf21a03249decadc86f4b90711fe8a53b0e;p=spider.git diff --git a/cmd/show/badip.pl b/cmd/show/badip.pl index 475abde1..832c98cd 100644 --- a/cmd/show/badip.pl +++ b/cmd/show/badip.pl @@ -1,7 +1,7 @@ # -# set list of bad dx nodes +# show (or find) list of bad dx nodes # -# Copyright (c) 2021 - Dirk Koopman G1TLH +# Copyright (c) 2021-2023 - Dirk Koopman G1TLH # # # @@ -9,41 +9,48 @@ my ($self, $line) = @_; return (1, $self->msg('e5')) if $self->remotecmd; # are we permitted? return (1, $self->msg('e5')) if $self->priv < 6; +return (1, q{Please install Net::CIDR::Lite or libnet-cidr-lite-perl to use this command}) unless $DXCIDR::active; + my @out; my @added; my @in = split /\s+/, $line; my $maxlth = 0; +my $width = $self->width // 80; +my $count = 0; -$DB::single = 1; - - -my @list = map {my $s = $_; $s =~ s|/32$||; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list(); -my @l; -$maxlth //= 20; -my $n = int (80/($maxlth+1)); -my $format = "\%-${maxlth}s " x $n; -chop $format; +#$DB::single = 1; -foreach my $list (@list) { - if (@in) { - for (@in) { - if ($list =~ /$_/i) { - push @out, $list; - last; - } +# query +if (@in) { + foreach my $ip (@in) { + if (DXCIDR::find($ip)) { + push @out, "$ip DIRTY"; + ++$count; + } else { + push @out, "$ip CLEAN"; } - } else { + } + return (1, @out); +} else { +# list + my @list = map {my $s = $_; $s =~ s!/(?:32|128)$!!; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list(); + my @l; + $maxlth //= 20; + my $n = int ($width/($maxlth+1)); + my $format = "\%-${maxlth}s " x $n; + chop $format; + + foreach my $list (@list) { + ++$count; if (@l > $n) { push @out, sprintf $format, @l; @l = (); } push @l, $list; - } -} -unless (@in) { + } push @l, "" while @l < $n; push @out, sprintf $format, @l; } -push @out, "show/badip: " . scalar @list . " records found"; +push @out, "show/badip: $count records found"; return (1, @out);