elvish_config/aliases/addbadips.elv

27 lines
566 B
Plaintext

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