diff --git a/aliases/addbadips.elv b/aliases/addbadips.elv index 4e73fe0..38c4ba4 100644 --- a/aliases/addbadips.elv +++ b/aliases/addbadips.elv @@ -4,31 +4,30 @@ edit:add-var addbadips~ {|@argv| use framagit.org/benjamin.vaudour/elv-lib/mods/list use framagit.org/benjamin.vaudour/elv-lib/mods/map - fn add {|f cmp ips| + fn add {|f cmp ips t| var @cips = (cat $f) var m c = (map:to-set $cips) 0 each {|e| if (not (has-key $m $e)) { - echo $e ajoutée - set c = (+ $c 1) set m[$e] = $nil set @cips = $@cips $e + set c = (+ $c 1) + echo $e ajoutée } } $ips if (> $c 0) { set @cips = (list:sort $cmp $cips) echo (str:join "\n" $cips) > $f } - put $c (count $cips) + printf "%d %s ajoutées (%d au total)\n" $c $t (count $cips) } + var ip4 ip6 = (list:filter $ip:is-ip~ $argv | list:unzip {|_ ip| ip:is-ipv4 $ip}) if (list:is-not-empty $ip4) { - var c t = (add $E:HOME/bad_ips.txt $ip:comp4~ $ip4) - printf "%d IPv4s ajoutées (%d au total)\n" $c $t + add $E:HOME/bad_ips.txt $ip:comp4~ $ip4 IPv4s } if (list:is-not-empty $ip6) { - var c t = (add $E:HOME/bad_ipsv6.txt $ip:comp6~ $ip6) - printf "%d IPv6s ajoutées (%d au total)\n" $c $t + add $E:HOME/bad_ipsv6.txt $ip:comp6~ $ip6 IPv6s } }