27 lines
810 B
Bash
Executable File
27 lines
810 B
Bash
Executable File
#!/bin/bash
|
|
# FILE: wgapi:back/lib/ns/lookup/rdns
|
|
# 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}"
|
|
|
|
domain="$(${LIB_DIR}/ns_lookup_send ${1})"
|
|
case $? in
|
|
0) printf "${domain%.}" | cut -d'=' -f2 | xargs -0; exit 0;;
|
|
4) printf "Address not found: ${1}\n" >>"${LOGFILE}"; exit 4;;
|
|
5) printf "Nameserver not available: ${DNS_MASTER}\n" >>"${LOGFILE}"; exit 5;;
|
|
6) printf 'nslookup not installed!\n' >>"${LOGFILE}"; exit 6;;
|
|
*) printf "Bad usage: ${0} ${@}\n" >>"${LOGFILE}"; exit 3;;
|
|
esac
|