summaryrefslogtreecommitdiff
path: root/getsrv
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2019-04-22 23:35:40 -0500
committerepoch <epoch@hacking.allowed.org>2019-04-22 23:35:40 -0500
commit5edf430271bb6c86fb0c9138aaf8915955fcd637 (patch)
treea31f49b553cbe436e1be569622babf96e4f37fc3 /getsrv
parent972c7ea8caa936b48273eb0ec0404fb4f7df5d26 (diff)
downloaduritools-5edf430271bb6c86fb0c9138aaf8915955fcd637.tar.gz
uritools-5edf430271bb6c86fb0c9138aaf8915955fcd637.zip
created script "getsrv" to get a single weighted host and port from SRV records
Diffstat (limited to 'getsrv')
-rwxr-xr-xgetsrv36
1 files changed, 36 insertions, 0 deletions
diff --git a/getsrv b/getsrv
new file mode 100755
index 0000000..cb6daeb
--- /dev/null
+++ b/getsrv
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+if [ "_$1" = '_-a' ];then
+ head="uniq"
+ shift
+else
+ head="head -n1"
+fi
+record="_$1._$2.$3"
+shift 3
+if [ "_$*" != "_" ];then
+ filter='grep -vF "'"$(printf "%s\n" "$*" | tr ' ' '\n')"'"'
+else
+ filter=cat
+fi
+if which dig >/dev/null;then
+ dig +short -t SRV "$record"
+ echo "after dig" >&2
+elif which host >/dev/null;then
+ host -t SRV "$record" | cut '-d ' -f5-
+ echo "after host" >&2
+else
+ echo "fuck me. how am I supposed to get a srv record without dig or host?" >&2
+ exit 1
+fi | grep '^[0-9][0-9]* [0-9][0-9]*' \
+ | sort -rn \
+ | rev \
+ | cut -b2- \
+ | rev \
+ | awk '{print $1, $2, $4":"$3}' \
+ | eval "$filter" \
+ | awk '{if(NR==1){D=$1}if(D==$1)print $0}' \
+ | cut '-d ' -f2- \
+ | awk '{for(i=0;i<=$1;i++) {print $0} }' \
+ | cut '-d ' -f2- \
+ | shuf \
+ | head -n1 \