2024-06-16 10:18:51 +00:00
|
|
|
edit:add-var dig-all~ {|@argv|
|
2024-02-11 18:37:36 +00:00
|
|
|
use re
|
2020-07-22 09:24:43 +00:00
|
|
|
use str
|
2021-12-27 17:54:26 +00:00
|
|
|
use framagit.org/benjamin.vaudour/elv-lib/mods/common
|
|
|
|
use framagit.org/benjamin.vaudour/elv-lib/mods/format
|
|
|
|
use framagit.org/benjamin.vaudour/elv-lib/mods/list
|
2020-07-22 09:24:43 +00:00
|
|
|
|
2021-08-27 19:45:39 +00:00
|
|
|
var default_records = [
|
2020-07-22 09:24:43 +00:00
|
|
|
A
|
|
|
|
AAAA
|
|
|
|
CNAME
|
|
|
|
PTR
|
|
|
|
TXT
|
|
|
|
MX
|
|
|
|
SRV
|
|
|
|
NAPTR
|
|
|
|
NS
|
|
|
|
SOA
|
|
|
|
]
|
2021-08-27 19:45:39 +00:00
|
|
|
var records servers = [] []
|
2021-10-13 18:43:40 +00:00
|
|
|
var flags = [
|
2020-07-22 09:24:43 +00:00
|
|
|
+noall
|
|
|
|
+answer
|
|
|
|
]
|
2021-08-27 19:45:39 +00:00
|
|
|
var domains use_dig = [] $true
|
2021-12-27 17:54:26 +00:00
|
|
|
|
|
|
|
fn init {
|
|
|
|
if (and (list:is-not-empty $argv) (eq $argv[0] -d)) {
|
|
|
|
set use_dig argv = $false $argv[1..]
|
2020-07-22 10:41:38 +00:00
|
|
|
}
|
2021-12-11 21:09:02 +00:00
|
|
|
each {|e|
|
2021-12-27 17:54:26 +00:00
|
|
|
if (eq $e[0] +) {
|
|
|
|
set @flags = $@flags $e
|
|
|
|
} elif (eq $e[0] @) {
|
|
|
|
set @servers = $@servers $e
|
|
|
|
} elif (list:contains $e $default_records) {
|
|
|
|
set @records = $@records $e
|
2020-07-22 09:24:43 +00:00
|
|
|
} else {
|
2021-12-27 17:54:26 +00:00
|
|
|
set @domains = $@domains $e
|
2020-07-22 09:24:43 +00:00
|
|
|
}
|
2021-08-24 18:44:01 +00:00
|
|
|
} $argv
|
2021-12-27 17:54:26 +00:00
|
|
|
if (list:is-empty $records) {
|
2021-10-13 18:43:40 +00:00
|
|
|
set records = $default_records
|
2020-07-22 09:24:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-27 17:54:26 +00:00
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn format {|results|
|
2024-02-11 18:37:36 +00:00
|
|
|
re:awk {|_ @args|
|
2021-08-24 18:44:01 +00:00
|
|
|
put [ $args[0] (all $args[2..]) ]
|
2021-12-11 21:09:02 +00:00
|
|
|
} $results | list:remove-duplicate | list:sort {|l1 l2|
|
2021-12-27 17:54:26 +00:00
|
|
|
var c = (compare $l1[0] $l2[0])
|
2020-07-22 14:35:25 +00:00
|
|
|
if (== $c 0) {
|
2021-12-27 17:54:26 +00:00
|
|
|
set c = (compare $l1[2] $l2[2])
|
2020-07-22 14:35:25 +00:00
|
|
|
}
|
2021-12-27 17:54:26 +00:00
|
|
|
put $c
|
|
|
|
} | each {|e| str:join ' ' $e} | format:tabulate
|
2020-07-22 14:35:25 +00:00
|
|
|
}
|
2021-12-27 17:54:26 +00:00
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn drillr {|d @args|
|
2021-12-27 17:54:26 +00:00
|
|
|
var @results = (peach {|r|
|
2021-12-11 21:09:02 +00:00
|
|
|
e:drill $@args $r $d | list:filter {|e|
|
2021-12-27 17:54:26 +00:00
|
|
|
and (> (count $e) 2) (not-eq $e[..2] ';;')
|
2020-07-22 10:41:38 +00:00
|
|
|
}
|
2021-12-27 17:54:26 +00:00
|
|
|
} $records)
|
2020-07-22 14:35:25 +00:00
|
|
|
format $results
|
2020-07-22 10:41:38 +00:00
|
|
|
}
|
2020-07-22 09:24:43 +00:00
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn digr {|d @args|
|
2021-12-27 17:54:26 +00:00
|
|
|
var @results = (peach {|r|
|
2020-07-22 09:24:43 +00:00
|
|
|
e:dig $@args $r $d $@flags
|
2021-12-27 17:54:26 +00:00
|
|
|
} $records)
|
2020-07-22 14:35:25 +00:00
|
|
|
format $results
|
2020-07-22 09:24:43 +00:00
|
|
|
}
|
2021-12-27 17:54:26 +00:00
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn req {|d @args|
|
2021-12-27 17:54:26 +00:00
|
|
|
common:cexec $use_dig { digr $d $@args } { drillr $d $@args }
|
2020-07-22 10:41:38 +00:00
|
|
|
}
|
2021-12-27 17:54:26 +00:00
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn digs {|s d|
|
2020-07-22 14:35:25 +00:00
|
|
|
put (echo (styled $s bright-yellow))
|
2020-07-22 10:41:38 +00:00
|
|
|
req $d $s
|
2020-07-22 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn digd {|d|
|
2021-12-27 17:54:26 +00:00
|
|
|
var @results = (echo (styled 'Domaine: '$d bright-green))
|
|
|
|
if (list:is-not-empty $servers) {
|
2021-12-11 21:09:02 +00:00
|
|
|
each {|s|
|
2021-10-13 18:43:40 +00:00
|
|
|
set @results = $@results (digs $s $d)
|
2020-07-22 09:24:43 +00:00
|
|
|
} $servers
|
|
|
|
} else {
|
2021-10-13 18:43:40 +00:00
|
|
|
set @results = $@results (req $d)
|
2020-07-22 09:24:43 +00:00
|
|
|
}
|
2020-07-22 14:35:25 +00:00
|
|
|
echo (str:join "\n" $results)
|
2020-07-22 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init
|
2020-07-22 14:35:25 +00:00
|
|
|
peach $digd~ $domains
|
2020-07-22 09:24:43 +00:00
|
|
|
}
|