elvish_config/aliases/digall.elv

109 lines
2.0 KiB
Plaintext
Raw Normal View History

2020-07-22 09:24:43 +00:00
#alias:new digall e:dig ANY +noall +answer
fn digall [@_args]{
use moi/util/list
use moi/util/strutil
2020-07-22 09:24:43 +00:00
use str
local:default_records = [
A
AAAA
CNAME
PTR
TXT
MX
SRV
NAPTR
NS
SOA
]
local:cols = [
[&min=24]
[&min=8]
[&min=10]
]
2020-07-22 09:24:43 +00:00
local:records = []
local:servers = []
local:flags = [
+noall
+answer
]
local:domains = []
local:use_dig = $true
2020-07-22 09:24:43 +00:00
fn init []{
if (and (> (count $_args) 0) (is $_args[0] -d)) {
use_dig = $false
_args = $_args[1:]
}
2020-07-22 09:24:43 +00:00
each [e]{
if (is $e[0] '+') {
flags = [ (all $flags) $e ]
} elif (is $e[0] @) {
servers = [ (all $servers) $e ]
} elif (list:includes $e $default_records) {
records = [ (all $records) $e ]
} else {
domains = [ (all $domains) $e ]
}
} $_args
if (== (count $records) 0) {
records = $default_records
}
}
fn format [results]{
eawk [_ @args]{
put [ $args[0] (all $args[2:]) ]
} $results | list:remove-duplicate | list:sort [l1 l2]{
local:c = (str:compare $l1[0] $l2[0])
if (== $c 0) {
c = (str:compare $l1[2] $l2[2])
}
} | strutil:format &col=$cols | str:join "\n"
}
fn drillr [d @args]{
local:results = [ (peach [r]{
e:drill $@args $r $d | list:filter [e]{
and (> (count $e) 2) (not (is $e[:2] ';;'))
}
} $records) ]
format $results
}
2020-07-22 09:24:43 +00:00
fn digr [d @args]{
local:results = [ (peach [r]{
2020-07-22 09:24:43 +00:00
e:dig $@args $r $d $@flags
} $records) ]
format $results
2020-07-22 09:24:43 +00:00
}
fn req [d @args]{
if $use_dig {
digr $d $@args
} else {
drillr $d $@args
}
}
2020-07-22 09:24:43 +00:00
fn digs [s d]{
put (echo (styled $s bright-yellow))
req $d $s
2020-07-22 09:24:43 +00:00
}
fn digd [d]{
local:results = [ (echo (styled 'Domaine: '$d bright-green)) ]
2020-07-22 09:24:43 +00:00
if (> (count $servers) 0) {
each [s]{
@results = $@results (digs $s $d)
2020-07-22 09:24:43 +00:00
} $servers
} else {
@results = $@results (req $d)
2020-07-22 09:24:43 +00:00
}
echo (str:join "\n" $results)
2020-07-22 09:24:43 +00:00
}
init
peach $digd~ $domains
2020-07-22 09:24:43 +00:00
}