elvish_config/aliases/addbadips.elv

34 lines
906 B
Plaintext

edit:add-var addbadips~ {|@argv|
use str
use framagit.org/benjamin.vaudour/elv-lib/mods/ip
use framagit.org/benjamin.vaudour/elv-lib/mods/list
use framagit.org/benjamin.vaudour/elv-lib/mods/map
fn add {|f cmp ips t|
var @cips = (cat $f)
var m c = (map:to-set $cips) 0
each {|e|
if (not (has-key $m $e)) {
set m[$e] = $nil
set @cips = $@cips $e
set c = (+ $c 1)
echo $e ajoutée
}
} $ips
if (> $c 0) {
set @cips = (list:sort $cmp $cips)
echo (str:join "\n" $cips) > $f
}
printf "%d %s ajoutées (%d au total)\n" $c $t (count $cips)
}
var ip4 ip6 = (list:filter $ip:is-ip~ $argv | list:unzip {|_ ip| ip:is-ipv4 $ip})
if (list:is-not-empty $ip4) {
add $E:HOME/ips/bad_ips.txt $ip:comp4~ $ip4 IPv4s
}
if (list:is-not-empty $ip6) {
add $E:HOME/ips/bad_ipsv6.txt $ip:comp6~ $ip6 IPv6s
}
}