elvish_config/aliases/addbadips.elv

35 lines
975 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|
var @cips = (cat $f)
var m c = (map:to-set $cips) 0
each {|e|
if (not (has-key $m $e)) {
echo $e ajoutée
set c = (+ $c 1)
set m[$e] = $nil
set @cips = $@cips $e
}
} $ips
if (> $c 0) {
set @cips = (list:sort $cmp $cips)
echo (str:join "\n" $cips) > $f
}
put $c (count $cips)
}
var ip4 ip6 = (list:filter $ip:is-ip~ $argv | list:unzip {|_ ip| ip:is-ipv4 $ip})
if (list:is-not-empty $ip4) {
var c t = (add $E:HOME/bad_ips.txt $ip:comp4~ $ip4)
printf "%d IPv4s ajoutées (%d au total)\n" $c $t
}
if (list:is-not-empty $ip6) {
var c t = (add $E:HOME/bad_ipsv6.txt $ip:comp6~ $ip6)
printf "%d IPv6s ajoutées (%d au total)\n" $c $t
}
}