fix is_ipaddr? change pc92 A/D default
[spider.git] / cmd / show / badip.pl
index 73db65da76df80e96329a8b84b21035844f9263a..55fa556b8e675384e9ccd75d24439721d0ddfd16 100644 (file)
@@ -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,20 +9,46 @@ 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 @list= DXCIDR::list();
+my $maxlth = 0;
+my $width = $self->width // 80;
+
+#$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 ($width/($maxlth+1));
+my $format = "\%-${maxlth}s " x $n;
+chop $format;
+
+my $count = 0;
+
 foreach my $list (@list) {
        if (@in) {
-               for (@in) {
-                       if ($list =~ /$_/i) {
+               for my $in (@in) {
+                       if ($list =~ /$in/i) {
                                push @out, $list;
-                               last;
+                               ++$count;
                        }
                }
        } else {
-               push @out, $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: $count records found";
 return (1, @out);