2021-12-11 21:09:02 +00:00
|
|
|
edit:add-var ipof~ {|@argv|
|
2021-08-24 18:45:25 +00:00
|
|
|
use str
|
|
|
|
use moi/util/condition
|
|
|
|
use moi/util/ip
|
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn less {|cmp e1 e2| < ($cmp $e1 $e2) 0 }
|
2021-08-24 18:45:25 +00:00
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn sort-ip {|e1 e2|
|
2021-08-27 19:45:39 +00:00
|
|
|
var i1 = (condition:cset (ip:is-ipv4 $e1) 0 (condition:cset (ip:is-ipv6 $e1) 1 2))
|
|
|
|
var i2 = (condition:cset (ip:is-ipv4 $e2) 0 (condition:cset (ip:is-ipv6 $e2) 1 2))
|
2021-08-24 18:45:25 +00:00
|
|
|
if (!= $i1 $i2) {
|
|
|
|
< $i1 $i2
|
|
|
|
} elif (== $i1 2) {
|
|
|
|
<s $e1 $e2
|
|
|
|
} elif (== $i1 1) {
|
|
|
|
less $ip:cmp6~ $e1 $e2
|
|
|
|
} else {
|
|
|
|
less $ip:cmp4~ $e1 $e2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn dnssolve {|d|
|
2021-08-27 19:45:39 +00:00
|
|
|
var result = [
|
2021-08-24 18:45:25 +00:00
|
|
|
&ips=[&]
|
|
|
|
&resolvers=''
|
|
|
|
&txt=''
|
|
|
|
]
|
2021-12-11 21:09:02 +00:00
|
|
|
e:dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml -resolve (idn -a $d) | peach {|l|
|
2021-09-01 13:55:25 +00:00
|
|
|
var ll = $l
|
|
|
|
var idx = (+ (str:index $ll :) 1)
|
|
|
|
var value = (str:trim-space $ll[$idx".."])
|
|
|
|
if (or (str:has-prefix $ll 'IPv4 addresses') (str:has-prefix $ll 'IPv6 addresses')) {
|
2021-12-11 21:09:02 +00:00
|
|
|
str:split ', ' $value | peach {|e|
|
2021-08-28 08:58:07 +00:00
|
|
|
var ee = $e
|
|
|
|
if (ip:is-ip $ee) {
|
2021-10-13 18:43:40 +00:00
|
|
|
set result[ips][$ee] = $nil
|
2021-08-24 18:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-01 13:55:25 +00:00
|
|
|
} elif (str:has-prefix $ll 'TXT records') {
|
2021-10-13 18:43:40 +00:00
|
|
|
set result[txt] = $value
|
2021-09-01 13:55:25 +00:00
|
|
|
} elif (str:has-prefix $ll 'Resolver') {
|
2021-10-13 18:43:40 +00:00
|
|
|
set result[resolvers] = $value
|
2021-09-01 13:55:25 +00:00
|
|
|
} elif (str:has-prefix $ll 'Name servers') {
|
2021-10-13 18:43:40 +00:00
|
|
|
set result[remote] = (not-eq $value 'name does not exist')
|
2021-08-24 18:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
put $result
|
|
|
|
}
|
|
|
|
|
2021-08-27 19:45:39 +00:00
|
|
|
var hosts = [&]
|
2021-12-11 21:09:02 +00:00
|
|
|
cat /etc/hosts | peach {|l|
|
2021-08-28 08:58:07 +00:00
|
|
|
var ll = (str:trim-space $l)
|
|
|
|
if (and (not-eq $ll '') (not-eq $ll[0] '#')) {
|
|
|
|
put $ll
|
2021-08-24 18:45:25 +00:00
|
|
|
}
|
2021-12-11 21:09:02 +00:00
|
|
|
} | eawk {|_ ip @domains|
|
|
|
|
peach {|d|
|
2021-08-28 08:58:07 +00:00
|
|
|
var dd = $d
|
|
|
|
if (has-key $hosts $dd) {
|
2021-10-13 18:43:40 +00:00
|
|
|
set hosts[$dd][$ip] = $nil
|
2021-08-24 18:45:25 +00:00
|
|
|
} else {
|
2021-10-13 18:43:40 +00:00
|
|
|
set hosts[$dd] = [&$ip=$nil]
|
2021-08-24 18:45:25 +00:00
|
|
|
}
|
|
|
|
} $domains
|
|
|
|
}
|
|
|
|
|
2021-08-27 19:45:39 +00:00
|
|
|
var remote = [&]
|
2021-12-11 21:09:02 +00:00
|
|
|
peach {|d|
|
2021-08-28 08:58:07 +00:00
|
|
|
var dd = $d
|
|
|
|
var solve = (dnssolve $dd)
|
2021-08-24 18:45:25 +00:00
|
|
|
if (> (keys $solve[ips] | count) 0) {
|
2021-10-13 18:43:40 +00:00
|
|
|
set remote[$dd] = $solve
|
2021-08-24 18:45:25 +00:00
|
|
|
}
|
|
|
|
} $argv
|
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
each {|d|
|
2021-08-27 19:45:39 +00:00
|
|
|
var exists = $false
|
2021-08-24 18:45:25 +00:00
|
|
|
echo (styled 'Resolving '$d'…' bright-green)
|
|
|
|
echo
|
|
|
|
if (has-key $hosts $d) {
|
2021-10-13 18:43:40 +00:00
|
|
|
set exists = $true
|
2021-08-24 18:45:25 +00:00
|
|
|
echo (styled ' local:' bright-yellow)
|
2021-12-11 21:09:02 +00:00
|
|
|
keys $hosts[$d] | order &less-than=$sort-ip~ | each {|ip|
|
2021-08-24 18:45:25 +00:00
|
|
|
echo ' - '$ip
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (and (has-key $remote $d) $remote[$d][remote]) {
|
2021-10-13 18:43:40 +00:00
|
|
|
set exists = $true
|
2021-08-27 19:45:39 +00:00
|
|
|
var info = $remote[$d]
|
2021-08-24 18:45:25 +00:00
|
|
|
echo (styled ' remote:' bright-yellow)
|
|
|
|
echo ' IPs:'
|
2021-12-11 21:09:02 +00:00
|
|
|
keys $info[ips] | order &less-than=$sort-ip~ | each {|ip|
|
2021-08-24 18:45:25 +00:00
|
|
|
echo ' - '$ip
|
|
|
|
}
|
|
|
|
echo ' Resolvers: '$info[resolvers]
|
|
|
|
echo ' TXT records: '$info[txt]
|
|
|
|
}
|
|
|
|
if (not $exists) {
|
|
|
|
echo (styled 'No info found' bright-red)
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
} $argv
|
|
|
|
}
|