elvish_config/aliases/addbadips.elv

26 lines
570 B
Plaintext
Raw Normal View History

2021-12-11 21:09:02 +00:00
edit:add-var addbadips~ {|@argv|
2021-08-24 18:45:25 +00:00
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
2021-12-11 21:09:02 +00:00
each {|e|
var cond = (and (not (has-key $m $e)) (ip:is-ipv4 $e))
2021-08-24 18:45:25 +00:00
if $cond {
echo $e ajoutée
2021-10-13 18:43:40 +00:00
set c = (+ $c 1)
set m[$e] = $nil
set ips = [ (all $ips) $e ]
2021-08-24 18:45:25 +00:00
}
} $argv
if (> $c 0) {
2021-10-13 18:43:40 +00:00
set ips = [ (list:sort $ip:cmp4~ $ips) ]
2021-08-24 18:45:25 +00:00
}
var result = (str:join "\n" $ips)
2021-08-24 18:45:25 +00:00
echo $result > $f
echo $c' IPs ajoutées ('(count $ips)' au total)'
}