elvish_config/aliases/digall.elv

91 lines
1.6 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 str
local:default_records = [
A
AAAA
CNAME
PTR
TXT
MX
SRV
NAPTR
NS
SOA
]
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 drillr [d @args]{
local:results = [ (peach [r]{
e:drill $@args $r $d | list:filter [e]{
and (> (count $e) 2) (not (is $e[:2] ';;'))
}
} $records | list:remove-duplicate) ]
echo (str:join "\n" $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 | list:remove-duplicate) ]
2020-07-22 09:24:43 +00:00
echo (str:join "\n" $results)
}
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]{
echo (styled $s bright-yellow)
req $d $s
2020-07-22 09:24:43 +00:00
}
fn digd [d]{
echo (styled 'Domaine: '$d bright-green)
if (> (count $servers) 0) {
each [s]{
digs $s $d
} $servers
} else {
req $d
2020-07-22 09:24:43 +00:00
}
}
init
each $digd~ $domains
}