29 lines
615 B
Plaintext
29 lines
615 B
Plaintext
|
#alias:new add_badips e:echo
|
||
|
fn add_badips [@_args]{
|
||
|
use moi/util/ip
|
||
|
use moi/util/list
|
||
|
use moi/util/map
|
||
|
use moi/util/number
|
||
|
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 = (number:++ $c)
|
||
|
m[$e] = $nil
|
||
|
ips = [ (all $ips) $e ]
|
||
|
}
|
||
|
} $_args
|
||
|
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)'
|
||
|
}
|