wagon/back/lib/ns_lookup_rdns

27 lines
798 B
Plaintext
Raw Normal View History

2022-09-06 20:57:41 -06:00
#!/bin/bash
2022-10-03 10:45:30 -06:00
# FILE: wgapi:back/lib/ns_lookup_rdns
2022-09-06 20:57:41 -06:00
# DESCRIPTION: Get a domain from an IP address
# USAGE: rdns ip
# OUTPUT: The domain for that IP
# ERRORS:
# 3: bad usage
# 4: not found
# 5: server down
# 6: nslookup not found
# 7: config not found
# Accept exactly one argument
[ ${#} -eq 1 ] || exit 3
CONFIG_FILE='/etc/wgapi/config'
[ -f "${CONFIG_FILE}" ] || exit 7
source "${CONFIG_FILE}"
2022-09-08 21:15:30 -06:00
domain="$("${LIB_DIR}/ns_lookup_send" "${1}")"
2022-09-06 20:57:41 -06:00
case $? in
2022-09-08 21:15:30 -06:00
0) printf '%s' "${domain%.}" | cut -d'=' -f2 | xargs -0; exit 0;;
4) printf 'Domain for %s not found!\n' "${1}" >&2; exit 4;;
5) printf 'Nameserver not available: %s\n' "${DNS_MASTER}" >&2; exit 5;;
6) printf 'nslookup not installed!\n' >&2; exit 6;;
*) printf 'Bad usage: %s %s\n' "${0}" "${@}" >&2; exit 3;;
2022-09-06 20:57:41 -06:00
esac