fix is_ipaddr? change pc92 A/D default
[spider.git] / cmd / show / badip.pl
1 #
2 # show (or find) list of bad dx nodes
3 #
4 # Copyright (c) 2021-2023 - Dirk Koopman G1TLH
5 #
6 #
7 #
8 my ($self, $line) = @_;
9 return (1, $self->msg('e5')) if $self->remotecmd;
10 # are we permitted?
11 return (1, $self->msg('e5')) if $self->priv < 6;
12 return (1, q{Please install Net::CIDR::Lite or libnet-cidr-lite-perl to use this command}) unless $DXCIDR::active;
13
14 my @out;
15 my @added;
16 my @in = split /\s+/, $line;
17 my $maxlth = 0;
18 my $width = $self->width // 80;
19
20 #$DB::single = 1;
21
22 my @list = map {my $s = $_; $s =~ s|/32$||; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list();
23 my @l;
24 $maxlth //= 20;
25 my $n = int ($width/($maxlth+1));
26 my $format = "\%-${maxlth}s " x $n;
27 chop $format;
28
29 my $count = 0;
30
31 foreach my $list (@list) {
32         if (@in) {
33                 for my $in (@in) {
34                         if ($list =~ /$in/i) {
35                                 push @out, $list;
36                                 ++$count;
37                         }
38                 }
39         } else {
40                 ++$count;
41                 if (@l > $n) {
42                         push @out, sprintf $format, @l;
43                         @l = ();
44                 }
45                 push @l, $list;
46         }
47 }       
48 unless (@in) {
49         push @l, "" while @l < $n;
50         push @out, sprintf $format, @l;
51 }
52
53 push @out, "show/badip: $count records found";
54 return (1, @out);