From eab4dd464a33f526d1917bfbccda3d14a0edfc74 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Wed, 19 Sep 2018 00:01:33 -0500 Subject: [PATCH] Used function to replace repetitive code --- tab-sorcery.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tab-sorcery.sh b/tab-sorcery.sh index a956b8f..1b0b508 100644 --- a/tab-sorcery.sh +++ b/tab-sorcery.sh @@ -8,6 +8,11 @@ scan_domain=$1 scan_ns=$2 +get_hostip () { + #host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'` + host_ip=`echo $zone_xfer | grep $1 | grep A | awk '{print $3}'` +} + zone_xfer=`dig $scan_domain @$scan_ns AXFR | egrep -v 'SOA|NS|MX|DiG' | grep $scan_domain | awk '{print $1,$4,$5}'` for host in `echo $zone_xfer | awk '{print $1}'`; do user_name=$3 @@ -16,22 +21,23 @@ for host in `echo $zone_xfer | awk '{print $1}'`; do if echo $zone_xfer | grep $host | grep TXT; then if [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"lxc"' ]; then user_name="root" - host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'` + get_hostip ${host} alias ${host_short}="${connect_cmd} ${user_name}@${host_ip}" elif [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"windows"' ]; then connect_cmd="rdesktop -g 1600x900" - host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'` + get_hostip ${host} alias ${host_short}="${connect_cmd} -u ${user_name} ${host_ip}" elif [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"cisco"' ]; then connect_cmd="telnet" - host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'` + get_hostip ${host} alias ${host_short}="${connect_cmd} ${host_ip}" fi else - host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` + get_hostip ${host} alias ${host_short}="${connect_cmd} ${user_name}@${host_ip}" fi >/dev/null done +unset -f get_hostip return 0