]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Starting with scripts/test-resolv
authorFrank Brehm <frank@brehm-online.com>
Wed, 31 Aug 2022 14:42:06 +0000 (16:42 +0200)
committerFrank Brehm <frank@brehm-online.com>
Wed, 31 Aug 2022 14:42:06 +0000 (16:42 +0200)
scripts/test-resolv [new file with mode: 0644]

diff --git a/scripts/test-resolv b/scripts/test-resolv
new file mode 100644 (file)
index 0000000..cfc8799
--- /dev/null
@@ -0,0 +1,212 @@
+#!/bin/bash
+
+set -e
+set -u
+
+BASE_NAME="$( basename ${0} )"
+MY_REAL_NAME=$( readlink -f $0 )
+BIN_DIR=$( dirname "${MY_REAL_NAME}" )
+BASE_DIR=$( dirname "${BIN_DIR}" )
+LIB_DIR="${BASE_DIR}/lib"
+CONF_DIR="${BASE_DIR}/etc"
+
+if [[ -f "${BIN_DIR}/functions.rc" ]] ; then
+    . "${BIN_DIR}/functions.rc"
+else
+    echo "Bash resource file '${BIN_DIR}/functions.rc' not found" >&2
+    exit 5
+fi
+
+MAX_TTL=10
+
+declare -a RESOLVERS=()
+declare -A RESOLVER_IPS=()
+
+RESOLVERS+=( 'ns1-local.pixelpark.com eth0:0' )
+RESOLVER_IPS['ns1-local.pixelpark.com eth0:0']='217.66.51.54'
+
+RESOLVERS+=( 'ns1-local.pixelpark.com eth1:0' )
+RESOLVER_IPS['ns1-local.pixelpark.com eth1:0']='217.66.52.9'
+
+RESOLVERS+=( 'ns1-local.pixelpark.com eth1:1' )
+RESOLVER_IPS['ns1-local.pixelpark.com eth1:1']='217.66.52.10'
+
+RESOLVERS+=( 'ns1-local.pixelpark.com eth2:0' )
+RESOLVER_IPS['ns1-local.pixelpark.com eth2:0']='217.66.55.21'
+
+RESOLVERS+=( 'ns1-local.pixelpark.com eth3:0' )
+RESOLVER_IPS['ns1-local.pixelpark.com eth3:0']='93.188.109.11'
+
+RESOLVERS+=( 'ns2-local.pixelpark.com eth0:0' )
+RESOLVER_IPS['ns2-local.pixelpark.com eth0:0']='93.188.109.12'
+
+RESOLVERS+=( 'ns2-local.pixelpark.com eth1:0' )
+RESOLVER_IPS['ns2-local.pixelpark.com eth1:0']='212.91.225.76'
+
+RESOLVERS+=( 'ns2-local.pixelpark.com eth1:1' )
+RESOLVER_IPS['ns2-local.pixelpark.com eth1:1']='212.91.225.75'
+
+RESOLVERS+=( 'ns2-local.pixelpark.com eth2:0' )
+RESOLVER_IPS['ns2-local.pixelpark.com eth2:0']='217.66.51.185'
+
+#-------------------------------------------------------------------------
+detect_color
+
+DESCRIPTION=$( cat <<-EOF
+       Iterates through all IP addresses of our internal resolvers and tries
+    to trace TCP port 53 (DNS) to it.
+
+       EOF
+)
+
+#------------------------------------------------------------------------------
+usage() {
+    cat <<-EOF
+    Usage: ${BASE_NAME} [Common Options] [-m MAX_TTL]
+              ${BASE_NAME} [-h|--help]
+              ${BASE_NAME} [-V|--version]
+
+           Options:
+               -m|--max-ttl MAX_TTL
+                               Specifies the maximum number of hops (max time-to-live value)
+                               traceroute will probe. The default is ${MAX_TTL}.
+       EOF
+
+    echo
+    echo "    Common Options:"
+    echo "${STD_USAGE_MSG}"
+
+}
+
+#------------------------------------------------------------------------------
+get_options() {
+
+    local tmp=
+    local base_dir=
+
+    local short_options="m:${STD_SHORT_OPTIONS}"
+    local long_options="max-ttl:,${STD_LONG_OPTIONS}"
+
+    set +e
+    tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASE_NAME}" -- "$@" )
+    if [[ $? != 0 ]] ; then
+        echo "" >&2
+        usage >&2
+        exit 1
+    fi
+    set -e
+
+    # Note the quotes around `$TEMP': they are essential!
+    eval set -- "${tmp}"
+    eval_common_options "$@"
+    if [[ "${DEBUG}" == 'y' ]] ; then
+        declare -p REMAINING_OPTS
+        declare -p REMAINING_ARGS
+    fi
+
+    local len="${#REMAINING_OPTS[*]}"
+    local i="0"
+    local j=
+    local arg=
+    while [[ "$i" -lt "${len}" ]] ; do
+
+        arg="${REMAINING_OPTS[$i]}"
+
+        case "${arg}" in
+            -m|--max-ttl)
+                j=$(( $i + 1 ))
+                MAX_TTL="${REMAINING_OPTS[$j]}"
+                i=$(( $i + 2 ))
+                ;;
+            *)  echo -e "Internal error - option '${RED}${arg}${NORMAL} was wrong!"
+                exit 1
+                ;;
+        esac
+    done
+
+    if [[ "${#REMAINING_ARGS[@]}" != "0" ]] ; then
+        error "Invalid arguments given."
+        echo >&2
+        usage >&2
+        exit 1
+    fi
+
+    local int_val=
+    local wrong_keep_vals="n"
+
+    int_val=$(( $MAX_TTL + 0 ))
+    if [[ "${int_val}" -le "0" ]] ; then
+        error "Invalid number of max TTL '${RED}${MAX_TTL}${NORMAL}'."
+        wrong_keep_vals="y"
+    fi
+
+    if [[ "${wrong_keep_vals}" == "y" ]] ; then
+        echo >&2
+        description >&2
+        echo
+        usage >&2
+        exit 1
+    fi
+
+    if command -pv tcptraceroute >/dev/null ; then
+        :
+    else
+        error "Command '${RED}tcptraceroute${NORMAL}' not found."
+        echo >&2
+        exit 3
+    fi
+
+}
+
+#------------------------------------------------------------------------------
+trace_ip() {
+
+    local resolver="$1"
+    local ip="$2"
+
+    empty_line
+    info "Tracing IP '${CYAN}${ip}${NORMAL}' (${resolver}) ..."
+
+}
+
+#------------------------------------------------------------------------------
+tracing_all_ips() {
+
+    local resolver=
+    local ip=
+
+    for resolver in "${RESOLVERS[@]}" ; do
+
+        ip="${RESOLVER_IPS[${resolver}]}"
+        trace_ip "${resolver}" "${ip}"
+
+    done
+
+}
+
+################################################################################
+##
+## Main
+##
+################################################################################
+
+#------------------------------------------------------------------------------
+main() {
+
+    get_options "$@"
+
+    set_locale 'en_US.utf8'
+
+    info "Starting ..."
+    tracing_all_ips
+
+    empty_line
+    info "Finished."
+
+}
+
+main "$@"
+
+exit 0
+
+# vim: ts=4 et list