2021-08-24 18:45:25 +00:00
|
|
|
edit:add-var ipof~ [@argv]{
|
|
|
|
use str
|
|
|
|
use moi/util/condition
|
|
|
|
use moi/util/ip
|
|
|
|
|
|
|
|
fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 }
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dnssolve [d]{
|
2021-08-27 19:45:39 +00:00
|
|
|
var result = [
|
2021-08-24 18:45:25 +00:00
|
|
|
&ips=[&]
|
|
|
|
&resolvers=''
|
|
|
|
&txt=''
|
|
|
|
]
|
|
|
|
e:dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml -resolve (idn -a $d) | peach [l]{
|
2021-08-27 19:45:39 +00:00
|
|
|
var l = $l
|
|
|
|
var idx = (+ (str:index $l :) 1)
|
|
|
|
var value = (str:trim-space $l[$idx".."])
|
2021-08-24 18:45:25 +00:00
|
|
|
if (or (str:has-prefix $l 'IPv4 addresses') (str:has-prefix $l 'IPv6 addresses')) {
|
|
|
|
str:split ', ' $value | peach [e]{
|
2021-08-27 19:45:39 +00:00
|
|
|
var e = $e
|
2021-08-24 18:45:25 +00:00
|
|
|
if (ip:is-ip $e) {
|
|
|
|
result[ips][$e] = $nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elif (str:has-prefix $l 'TXT records') {
|
|
|
|
result[txt] = $value
|
|
|
|
} elif (str:has-prefix $l 'Resolver') {
|
|
|
|
result[resolvers] = $value
|
|
|
|
} elif (str:has-prefix $l 'Name servers') {
|
|
|
|
result[remote] = (not-eq $value 'name does not exist')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
put $result
|
|
|
|
}
|
|
|
|
|
2021-08-27 19:45:39 +00:00
|
|
|
var hosts = [&]
|
2021-08-24 18:45:25 +00:00
|
|
|
cat /etc/hosts | peach [l]{
|
2021-08-27 19:45:39 +00:00
|
|
|
var l = $l
|
2021-08-24 18:45:25 +00:00
|
|
|
l = (str:trim-space $l)
|
|
|
|
if (and (not-eq $l '') (not-eq $l[0] '#')) {
|
|
|
|
put $l
|
|
|
|
}
|
|
|
|
} | eawk [_ ip @domains]{
|
|
|
|
peach [d]{
|
2021-08-27 19:45:39 +00:00
|
|
|
var d = $d
|
2021-08-24 18:45:25 +00:00
|
|
|
if (has-key $hosts $d) {
|
|
|
|
hosts[$d][$ip] = $nil
|
|
|
|
} else {
|
|
|
|
hosts[$d] = [&$ip=$nil]
|
|
|
|
}
|
|
|
|
} $domains
|
|
|
|
}
|
|
|
|
|
2021-08-27 19:45:39 +00:00
|
|
|
var remote = [&]
|
2021-08-24 18:45:25 +00:00
|
|
|
peach [d]{
|
2021-08-27 19:45:39 +00:00
|
|
|
var d = $d
|
|
|
|
var solve = (dnssolve $d)
|
2021-08-24 18:45:25 +00:00
|
|
|
if (> (keys $solve[ips] | count) 0) {
|
|
|
|
remote[$d] = $solve
|
|
|
|
}
|
|
|
|
} $argv
|
|
|
|
|
|
|
|
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) {
|
|
|
|
exists = $true
|
|
|
|
echo (styled ' local:' bright-yellow)
|
|
|
|
keys $hosts[$d] | order &less-than=$sort-ip~ | each [ip]{
|
|
|
|
echo ' - '$ip
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (and (has-key $remote $d) $remote[$d][remote]) {
|
|
|
|
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:'
|
|
|
|
keys $info[ips] | order &less-than=$sort-ip~ | each [ip]{
|
|
|
|
echo ' - '$ip
|
|
|
|
}
|
|
|
|
echo ' Resolvers: '$info[resolvers]
|
|
|
|
echo ' TXT records: '$info[txt]
|
|
|
|
}
|
|
|
|
if (not $exists) {
|
|
|
|
echo (styled 'No info found' bright-red)
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
} $argv
|
|
|
|
}
|