elvish_config/aliases/addbadips.elv

26 lines
570 B
Plaintext

edit:add-var addbadips~ [@argv]{
use moi/util/ip
use moi/util/list
use moi/util/map
use str
var f = ~/bad_ips.txt
var ips = [ (cat $f) ]
var m c = (map:to-set $ips) 0
each [e]{
var cond = (and (not (has-key $m $e)) (ip:is-ipv4 $e))
if $cond {
echo $e ajoutée
set c = (+ $c 1)
set m[$e] = $nil
set ips = [ (all $ips) $e ]
}
} $argv
if (> $c 0) {
set ips = [ (list:sort $ip:cmp4~ $ips) ]
}
var result = (str:join "\n" $ips)
echo $result > $f
echo $c' IPs ajoutées ('(count $ips)' au total)'
}