Fall back to an in-addr.arpa hostname when a PTR record is not available. dev/2018-05_up2speed
authorGeorgios Kontaxis <redacted>
Tue, 22 May 2018 21:25:23 +0000 (14:25 -0700)
committerGeorgios Kontaxis <redacted>
Tue, 22 May 2018 21:25:23 +0000 (14:25 -0700)
scan/_Makefile
scan/configure.sh

index 2f6f491847bab90bc11761ace76b2d1f1b560151..ef568b610b1584af7359da1f344731d6bea4ba9a 100644 (file)
@@ -1,6 +1,6 @@
 .PHONY: all clean
 
-hostname = "\"www.example.com\""
+hostname = "\"localhost.\""
 
 all: \
        bin/smtp_ssl3  bin/smtp_ssl3_god  bin/smtp_tls1  bin/smtp_tls1_god  \
index b6842e21bc4ab9aeedeb9193ffba690ffd207765..29f3548b6bda1903d7e6e2d1f919a138ae100120 100755 (executable)
@@ -1,18 +1,32 @@
 #!/bin/bash
 
-# make sure we have all the tools lying around
-  SEDBIN=`which sed  `; if [   "${SEDBIN}" == "" ]; then \
-               >&2 echo "FATAL. $0 FAILED. Missing sed.";   exit -1; fi
+# Make sure we have all the tools available.
  CURLBIN=`which curl `; if [  "${CURLBIN}" == "" ]; then \
                >&2 echo "FATAL. $0 FAILED. Missing curl.";  exit -1; fi
-XARGSBIN=`which xargs`; if [ "${XARGSBIN}" == "" ]; then \
-               >&2 echo "FATAL. $0 FAILED. Missing xargs."; exit -1; fi
   DIGBIN=`which dig  `; if [   "${DIGBIN}" == "" ]; then \
                >&2 echo "FATAL. $0 FAILED. Missing dig.";   exit -1; fi
+  AWKBIN=`which awk  `; if [   "${AWKBIN}" == "" ]; then \
+               >&2 echo "FATAL. $0 FAILED. Missing awk.";   exit -1; fi
+  SEDBIN=`which sed  `; if [   "${SEDBIN}" == "" ]; then \
+               >&2 echo "FATAL. $0 FAILED. Missing sed.";   exit -1; fi
+
+# Update the hostname variable in the Makefile with the FQDN of this host.
+myipaddr=$(curl -s --max-time 5 https://tools.100tx.org/myipaddress/)
+if [ "$myipaddr" == "" ]; then
+       myipaddr="127.0.0.1"
+fi
+
+myfqdn=$(dig +short -x $myipaddr 2> /dev/null)
+if [ "$myfqdn" == "" ]; then
+       myfqdn=$(echo "$myipaddr" | awk -F \. \
+               '{
+                       for (i = NF; i > 1; i--) {
+                               printf("%s.", $i);
+                       }
+                       printf("%s.in-addr.arpa.\n", $1);
+               }'
+       )
+fi
 
-# update the hostname variable in the Makefile with the actual name of this
-# host (so that reverse lookups match, ideally there's an MX record too but
-# that's may be asking too much)
-sed s/"^hostname = .*\$"/"hostname = \"\\\\\"`curl -s \
-       https://tools.100tx.org/myipaddress/ \
-       | xargs dig +short -x | sed s/"\.\$"//g`\\\\\"\""/g _Makefile > Makefile
+sed s/"^hostname = .*\$"/"hostname = \"\\\\\"$myfqdn\\\\\"\""/g \
+       _Makefile > Makefile
git clone https://git.99rst.org/PROJECT