2021-08-24 18:45:25 +00:00
|
|
|
edit:add-var addbadips~ [@argv]{
|
|
|
|
use moi/util/ip
|
|
|
|
use moi/util/list
|
|
|
|
use moi/util/map
|
|
|
|
use str
|
|
|
|
|
2021-08-27 19:45:39 +00:00
|
|
|
var f = ~/bad_ips.txt
|
|
|
|
var ips = [ (cat $f) ]
|
|
|
|
var m c = (map:to-set $ips) 0
|
2021-08-24 18:45:25 +00:00
|
|
|
each [e]{
|
2021-08-27 19:45:39 +00:00
|
|
|
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
|
|
|
}
|
2021-08-27 19:45:39 +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)'
|
|
|
|
}
|