Fist attempt at using AXFR
parent
f762242f70
commit
f6686ec7ac
|
@ -23,28 +23,41 @@ fi
|
|||
source "${CONFIG_FILE}"
|
||||
format="${1}"
|
||||
|
||||
|
||||
|
||||
# Loop through each peer in parallel and do an rDNS lookup for the hostnames
|
||||
do_lookup(){
|
||||
pubkey="$(<<<"${1}" cut -d ' ' -f1)"
|
||||
ips="$(<<<"${1}" cut -d ' ' -f2 | tr ' ' '\n')"
|
||||
ipv4="$(<<<"${ips}" grep '\.')"
|
||||
ipv6="$(<<<"${ips}" grep ':')"
|
||||
ipv4="${ipv4%%/*}"
|
||||
ipv6="${ipv6%%/*}"
|
||||
if ! domain="$("${LIB_DIR:?}/ns_lookup_rdns" "${ipv4:?}" | xargs)"
|
||||
then exit 4
|
||||
fi
|
||||
case "${format}" in
|
||||
'json') printf '{"domain":"%s","ipv4":"%s","ipv6":"%s","pubkey":"%s"},' \
|
||||
"${domain}" "${ipv4}" "${ipv6}" "${pubkey}";;
|
||||
'tsv') printf '%s\t%s\t%s\t%s\n' "${domain}" "${ipv4}" "${ipv6}" "${pubkey}";;
|
||||
*) printf 'ERROR! Invalid format for %s: %s\n' "${0}" "${format}" >>"${LOGFILE}"
|
||||
exit 5;
|
||||
esac
|
||||
}
|
||||
#do_lookup(){
|
||||
# pubkey="$(<<<"${1}" cut -d ' ' -f1)"
|
||||
# ips="$(<<<"${1}" cut -d ' ' -f2 | tr ' ' '\n')"
|
||||
# ipv4="$(<<<"${ips}" grep '\.')"
|
||||
# ipv6="$(<<<"${ips}" grep ':')"
|
||||
# ipv4="${ipv4%%/*}"
|
||||
# ipv6="${ipv6%%/*}"
|
||||
# if ! domain="$("${LIB_DIR:?}/ns_lookup_rdns" "${ipv4:?}" | xargs)"
|
||||
# then exit 4
|
||||
# fi
|
||||
# case "${format}" in
|
||||
# 'json') printf '{"domain":"%s","ipv4":"%s","ipv6":"%s","pubkey":"%s"},' \
|
||||
# "${domain}" "${ipv4}" "${ipv6}" "${pubkey}";;
|
||||
# 'tsv') printf '%s\t%s\t%s\t%s\n' "${domain}" "${ipv4}" "${ipv6}" "${pubkey}";;
|
||||
# *) printf 'ERROR! Invalid format for %s: %s\n' "${0}" "${format}" >>"${LOGFILE}"
|
||||
# exit 5;
|
||||
# esac
|
||||
#}
|
||||
|
||||
# Perform AXFR lookup
|
||||
if ! res="$("${LIB_DIR:?}/ns_lookup_rdns" "${ipv4:?}" | xargs)";
|
||||
then exit 4
|
||||
fi
|
||||
printf '%s\n' "${res}" >>"${LOGFILE}"
|
||||
|
||||
# This should read from stdin
|
||||
while IFS= read -r line
|
||||
do do_lookup "${line}" "${1}" &
|
||||
[ $( jobs | wc -l ) -ge $( nproc ) ] && wait
|
||||
done | sed 's/\n//g' | sed 's/,$//' # Remove trailing comma and newline
|
||||
do <<<"${res}" grep -B1 "${line}" >>"${LOGFILE}"
|
||||
done
|
||||
|
||||
# This should read from stdin
|
||||
#while IFS= read -r line
|
||||
# do do_lookup "${line}" "${1}" &
|
||||
# [ $( jobs | wc -l ) -ge $( nproc ) ] && wait
|
||||
#done | sed 's/\n//g' | sed 's/,$//' # Remove trailing comma and newline
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# FILE: wgapi:back/lib/ns/lookup/rdns
|
||||
# FILE: wgapi:back/lib/ns_lookup_rdns
|
||||
# DESCRIPTION: Get a domain from an IP address
|
||||
# USAGE: rdns ip
|
||||
# OUTPUT: The domain for that IP
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
# FILE: wgapi:back/lib/ns_lookup_rxfr
|
||||
# DESCRIPTION: Get all records
|
||||
# USAGE: ns_lookup_rxfr
|
||||
# OUTPUT: The complete set of records for the TLD
|
||||
# ERRORS:
|
||||
# 3: bad usage
|
||||
# 4: not found
|
||||
# 5: server down
|
||||
# 6: nslookup not found
|
||||
# 7: config not found
|
||||
# 8: nslookup refused
|
||||
# 9: nslookup error
|
||||
|
||||
# Accept no arguments
|
||||
[ ${#} -eq 0 ] || exit 3
|
||||
CONFIG_FILE='/etc/wgapi/config'
|
||||
[ -f "${CONFIG_FILE}" ] || exit 7
|
||||
source "${CONFIG_FILE}"
|
||||
|
||||
res="$("${LIB_DIR}/ns_lookup_send" "-query=AXFR" "${TLD}.")"
|
||||
case $? in
|
||||
0) printf '%s' "${res}"; exit 0;;
|
||||
4) printf 'Domain for %s not found!\n' "${1}" >>"${LOGFILE}"; exit 4;;
|
||||
5) printf 'Nameserver not available: %s\n' "${DNS_MASTER}" >>"${LOGFILE}"; exit 5;;
|
||||
6) printf 'nslookup not installed!\n' >>"${LOGFILE}"; exit 6;;
|
||||
8) printf 'nslookup threw an error!\n' >>"${LOGFILE}"; exit 9;;
|
||||
9) printf 'nslookup refused RXFR request!\n' >>"${LOGFILE}"; exit 8;;
|
||||
*) printf 'Bad usage: %s %s\n' "${0}" "${@}" >>"${LOGFILE}"; exit 3;;
|
||||
esac
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
# FILE: wgapi:back/lib/ns/lookup/send
|
||||
# FILE: wgapi:back/lib/ns_lookup_send
|
||||
# DESCRIPTION: Send nslookup command to DNS master server
|
||||
# USAGE: send cmd
|
||||
# USAGE: send [option] cmd
|
||||
# ERRORS:
|
||||
# 3: bad usage
|
||||
# 4: not found
|
||||
|
@ -9,19 +9,22 @@
|
|||
# 6: nslookup not found
|
||||
# 7: config file not found
|
||||
# 8: other nslookup error
|
||||
# 9: nslookup refused
|
||||
|
||||
CONFIG_FILE='/etc/wgapi/config'
|
||||
[ ${#} -eq 1 ] || exit 3
|
||||
[ ${#} -eq 1 ] || [ ${#} -eq 2 ] || exit 3
|
||||
[ -f "${CONFIG_FILE}" ] || exit 7
|
||||
[ -x /usr/bin/nslookup ] || exit 6
|
||||
source "${CONFIG_FILE}"
|
||||
|
||||
if ! res="$(/usr/bin/nslookup "${1}" "${DNS_MASTER}")"
|
||||
if ! res="$(/usr/bin/nslookup ${@} "${DNS_MASTER}")"
|
||||
then exit 8
|
||||
fi
|
||||
if <<<"${res}" grep ';; .* timed out'
|
||||
then exit 5
|
||||
elif <<<"${res}" grep "\*\* .*: NXDOMAIN\|\*\*\* .*: No answer"
|
||||
then exit 4
|
||||
elif <<<"${res}" grep "\*\* .*: REFUSED"
|
||||
then exit 9
|
||||
else printf '%s' "${res}"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue