elvish_config/aliases/addbadips.elv

35 lines
975 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 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
2021-08-24 18:45:25 +00:00
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
2021-08-24 18:45:25 +00:00
}
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
2021-08-24 18:45:25 +00:00
}
}