From fbd0ce0d7cb05f394393365c17013518f3655b68 Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 27 Nov 2021 23:37:57 +0100 Subject: [PATCH 01/13] add note files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b79c976..efcb29a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ hash +*.note From cb324fe66cee157664b9b467811d20b06ffb023f Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 27 Nov 2021 23:46:08 +0100 Subject: [PATCH 02/13] prepare branch --- README.md | 3 +++ conn.sh => conn.sh.old | 0 hash | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) rename conn.sh => conn.sh.old (100%) delete mode 100644 hash diff --git a/README.md b/README.md index 79f5fda..a7673fb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # conn + +__the script is actively being rewritten on this branch and might not be on a usable state right now__ + quick and dirty server availability check

basically just a way too complex wrapper for nmap and fping
diff --git a/conn.sh b/conn.sh.old similarity index 100% rename from conn.sh rename to conn.sh.old diff --git a/hash b/hash deleted file mode 100644 index 8e61e53..0000000 --- a/hash +++ /dev/null @@ -1 +0,0 @@ -4e4196dd964785b6b641302db031312b From 260bd376083e68174cad6d74fe4c574ffb486331 Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 28 Nov 2021 00:14:38 +0100 Subject: [PATCH 03/13] prepare skeleton --- conn.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 conn.sh diff --git a/conn.sh b/conn.sh new file mode 100755 index 0000000..4112636 --- /dev/null +++ b/conn.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# license: gpl-3 + +show_help="conn: a quick and dirty server availability check + +usage: + "$0" [IP(s)/hostname(s)] + +arguments: + -h / --help show help page (this) + -6 / --force-ipv6 force ipv6 portscanning (also forces portscanning) + -4 / --force-ipv4 force ipv4 portscanning (also forces portscanning) + -y / --yes portscan without asking + -n / --no dont portscan + -w / --wait wait for active connection + -u / --update update the script + -f / --fast disable os check + -s / --simple simplyfy output" + +show_notfound="[error] argument not found + +available arguments: + -h / --help show help page (this) + -6 / --force-ipv6 force ipv6 portscanning (also forces portscanning) + -4 / --force-ipv4 force ipv4 portscanning (also forces portscanning) + -y / --yes portscan without asking + -n / --no dont portscan + -w / --wait wait for active connection + -u / --update update the script + -f / --fast disable os check + -s / --simple simplify output" + +function prepare { + true +} + +function main { + true +} + +if [[ -n $1 ]];then + prepare + main +else + echo "$show_help" +fi \ No newline at end of file From acd564445e24e216dcc7b831d76b4138f1a93944 Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 28 Nov 2021 01:26:31 +0100 Subject: [PATCH 04/13] parse args --- conn.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/conn.sh b/conn.sh index 4112636..7c23707 100755 --- a/conn.sh +++ b/conn.sh @@ -15,7 +15,7 @@ arguments: -w / --wait wait for active connection -u / --update update the script -f / --fast disable os check - -s / --simple simplyfy output" + -s / --simple simplify output" show_notfound="[error] argument not found @@ -30,17 +30,72 @@ available arguments: -f / --fast disable os check -s / --simple simplify output" +function check_update { + if [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) != $(md5sum $0 | cut -c -32) ]] && [[ -z $1 ]] || [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) != $(md5sum $0 | cut -c -32) ]] && [[ $1 != "--update" ]] || [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) != $(md5sum $0 | cut -c -32) ]] && [[ $1 != "-u" ]];then + echo "#############################################" + echo -e "\e[4mnote: newer version detected, use -u to update\e[0m" + echo "#############################################" + echo "" + fi +} + +function run_update { + if [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) != $(md5sum $0 | cut -c -32) ]];then + wget -O $0 --quiet "https://raw.githubusercontent.com/byReqz/conn/main/conn.sh" + echo "#############################################" + echo -e "\e[4mscript has been updated to the newest version\e[0m" + echo "#############################################" + exit + elif [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) = $(md5sum $0 | cut -c -32) ]];then + echo "#############################################" + echo "no newer version found" + echo "#############################################" + exit + fi +} + function prepare { - true + #check_update + get_args $@ + set_argvars $args +} + +function get_args { + input=$(echo "$@") + args=$(echo "$input" | grep -o -e "-h" -e "--help" -e "-6" -e "--force-ipv6" -e "-4" -e "--force-ipv4" -e "-y" -e "--yes" -e "-n" -e "--no" -e "-w" -e "--wait" -e "-u" -e "--update" -e "-f" -e "--fast" -e "-s" -e "--simple" | xargs) + for arg in $args; do + input=$(echo "$input" | sed "s/$arg//g") + done + +# needs work +# argcheck=$(echo $input | grep -o -e " -* " | xargs) +# echo $argcheck +# if [[ -n "$argcheck" ]];then +# for arg in $argcheck; do +# echo "the given argument \""$arg"\" is not known" +# done +# fi +} + +function set_argvars { + if [[ $@ =~ -6 ]] || [[ $@ =~ --force-ipv6 ]];then + only6=true + fi } function main { - true + true } if [[ -n $1 ]];then - prepare - main + prepare $@ + main "$input" +elif [[ "$1" == "-u" ]];then + run_update +elif [[ "$1" == "-h" ]];then + check_update + echo "$show_help" else + #check_update echo "$show_help" fi \ No newline at end of file From 768479ca2f6e43ab38e09669ee021f7cf1ec35e4 Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 28 Nov 2021 15:40:45 +0100 Subject: [PATCH 05/13] add validate function --- conn.sh | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/conn.sh b/conn.sh index 7c23707..144b32e 100755 --- a/conn.sh +++ b/conn.sh @@ -58,6 +58,7 @@ function prepare { #check_update get_args $@ set_argvars $args + validate $input } function get_args { @@ -81,6 +82,36 @@ function set_argvars { if [[ $@ =~ -6 ]] || [[ $@ =~ --force-ipv6 ]];then only6=true fi + if [[ $@ =~ -4 ]] || [[ $@ =~ --force-ipv4 ]];then + only4=true + fi + if [[ $@ =~ -y ]] || [[ $@ =~ --yes ]];then + doportscan=true + fi + if [[ $@ =~ -n ]] || [[ $@ =~ --no ]];then + doportscan=false + fi + if [[ $@ =~ -s ]] || [[ $@ =~ --simple ]];then + simpleoutput=true + fi + if [[ $@ =~ -w ]] || [[ $@ =~ --wait ]];then + waitcheck=true + fi + if [[ $@ =~ -f ]] || [[ $@ =~ --fast ]];then + oscheck=false + fi +} + +function validate { + for arg in $@; do + if $(ip route show "$arg" 2&> /dev/null);then + hosts="$hosts $arg" + elif $(nslookup "$arg" > /dev/null);then + hosts="$hosts $arg" + else + echo "invalid input: $arg" + fi + done } function main { @@ -88,8 +119,8 @@ function main { } if [[ -n $1 ]];then - prepare $@ - main "$input" + prepare "$@" + main "$hosts" elif [[ "$1" == "-u" ]];then run_update elif [[ "$1" == "-h" ]];then From def8538bacb879081dd95da5fb12412303020e6c Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 28 Nov 2021 16:39:32 +0100 Subject: [PATCH 06/13] import skeleton and roughly adjust it --- conn.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/conn.sh b/conn.sh index 144b32e..b756bde 100755 --- a/conn.sh +++ b/conn.sh @@ -63,6 +63,7 @@ function prepare { function get_args { input=$(echo "$@") + echo $input args=$(echo "$input" | grep -o -e "-h" -e "--help" -e "-6" -e "--force-ipv6" -e "-4" -e "--force-ipv4" -e "-y" -e "--yes" -e "-n" -e "--no" -e "-w" -e "--wait" -e "-u" -e "--update" -e "-f" -e "--fast" -e "-s" -e "--simple" | xargs) for arg in $args; do input=$(echo "$input" | sed "s/$arg//g") @@ -80,10 +81,10 @@ function get_args { function set_argvars { if [[ $@ =~ -6 ]] || [[ $@ =~ --force-ipv6 ]];then - only6=true + only="-6" fi if [[ $@ =~ -4 ]] || [[ $@ =~ --force-ipv4 ]];then - only4=true + only="-4" fi if [[ $@ =~ -y ]] || [[ $@ =~ --yes ]];then doportscan=true @@ -115,7 +116,66 @@ function validate { } function main { - true + if [[ $simpleoutput == true ]] && [[ -n $hosts ]];then + echo "-------------------Availability----------------------" + fping $only -e $@ + quickport=$(nping $only -c1 -p22,222,3389,135 $@ | grep -e "completed") + if [[ -n $quickport ]];then + echo "" + echo "$quickport" + fi + echo "-----------------------------------------------------" + else + for host in $hosts;do + echo "checking connection status for $host" + fping=$(fping $only -a $host) + if [[ ! $oscheck == false ]];then + p135=$(nping $only -q1 -c1 -p135 $host) + p3389=$(nping $only -q1 -c1 -p3389 $host) + fi + if [[ $fping != "$host" ]] && [[ -n $(echo $p135 | grep "Successful connections: 1") ]] || [[ $fping != "$host" ]] && [[ -n $(echo $p3389 | grep "Successful connections: 1") ]];then + echo "-------------------Availability----------------------" + echo "note: this seems to be a windows machine which does not respond to ICMP" + echo "-----------------------------------------------------" + elif [[ $fping != "$host" ]] && [[ -z $(echo $p135 | grep "Successful connections: 1") ]] || [[ $fping != "$host" ]] && [[ -z $(echo $p3389 | grep "Successful connections: 1") ]];then + echo "-------------------Availability----------------------" + echo "$host is not reachable" + echo "-----------------------------------------------------" + else + echo "-------------------Availability----------------------" + fping $only -e $host + if [[ ! $oscheck == false ]];then + rescue=$(nping $only -q1 -c1 -p22,222 $host) + if [[ -n $(echo $rescue | grep "Successful connections: 1") ]];then + echo "note: this seems to be a linux machine" + elif [[ -n $(echo $rescue | grep "Successful connections: 2") ]];then + echo "note: this machine seems to be in the rescue system" + elif [[ -n $(echo $p135 | grep "Successful connections: 1") ]] || [[ -n $(echo $p3389 | grep "Successful connections: 1") ]];then + echo "note: this machine seems to be booted into windows" + fi + fi + echo "-----------------------------------------------------" + fi + if [[ ! $doportscan == false ]];then + if [[ $doportscan == true ]];then + portscan=y + else + echo "portscan? (y/n) (default: y)" + read portscan + fi + if [[ "$portscan" = "y" ]] || [[ -z "$portscan" ]]; then + echo "-------------------Portscan---------------------" + nmap $only --reason -Pn $host + echo "" + fping $only -c 4 $host + echo "------------------------------------------------" + exit + else + echo "" + fi + fi + done + fi } if [[ -n $1 ]];then From 97db5c1fb920b59003b094208ce29cb702e93d6b Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 28 Nov 2021 17:03:11 +0100 Subject: [PATCH 07/13] fix error with -n --- conn.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/conn.sh b/conn.sh index b756bde..46bc97e 100755 --- a/conn.sh +++ b/conn.sh @@ -56,14 +56,13 @@ function run_update { function prepare { #check_update - get_args $@ + get_args "$@" set_argvars $args validate $input } function get_args { - input=$(echo "$@") - echo $input + input=$(echo " $@") args=$(echo "$input" | grep -o -e "-h" -e "--help" -e "-6" -e "--force-ipv6" -e "-4" -e "--force-ipv4" -e "-y" -e "--yes" -e "-n" -e "--no" -e "-w" -e "--wait" -e "-u" -e "--update" -e "-f" -e "--fast" -e "-s" -e "--simple" | xargs) for arg in $args; do input=$(echo "$input" | sed "s/$arg//g") From c9de29f3ec6a2843de38afaecd3d3f0cb98738d8 Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 28 Nov 2021 17:24:21 +0100 Subject: [PATCH 08/13] import and adjust wait function --- conn.sh | 83 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 20 deletions(-) diff --git a/conn.sh b/conn.sh index 46bc97e..3601249 100755 --- a/conn.sh +++ b/conn.sh @@ -126,34 +126,77 @@ function main { echo "-----------------------------------------------------" else for host in $hosts;do - echo "checking connection status for $host" - fping=$(fping $only -a $host) - if [[ ! $oscheck == false ]];then - p135=$(nping $only -q1 -c1 -p135 $host) - p3389=$(nping $only -q1 -c1 -p3389 $host) - fi - if [[ $fping != "$host" ]] && [[ -n $(echo $p135 | grep "Successful connections: 1") ]] || [[ $fping != "$host" ]] && [[ -n $(echo $p3389 | grep "Successful connections: 1") ]];then - echo "-------------------Availability----------------------" - echo "note: this seems to be a windows machine which does not respond to ICMP" - echo "-----------------------------------------------------" - elif [[ $fping != "$host" ]] && [[ -z $(echo $p135 | grep "Successful connections: 1") ]] || [[ $fping != "$host" ]] && [[ -z $(echo $p3389 | grep "Successful connections: 1") ]];then - echo "-------------------Availability----------------------" - echo "$host is not reachable" - echo "-----------------------------------------------------" - else - echo "-------------------Availability----------------------" - fping $only -e $host + if [[ $waitcheck == true ]];then + echo "-w used, waiting for active connection" + echo "checking connection status for $host" + fping=$(fping $only -a $host) if [[ ! $oscheck == false ]];then - rescue=$(nping $only -q1 -c1 -p22,222 $host) + p135=$(nping $only -q1 -c1 -p135 $host) + p3389=$(nping $only -q1 -c1 -p3389 $host) + fi + if [[ $fping != "$host" ]] && [[ -n $(echo $p135 | grep "Successful connections: 1") ]] || [[ $fping != "$host" ]] && [[ -n $(echo $p3389 | grep "Successful connections: 1") ]];then + echo "-------------------Availability----------------------" + echo "note: this seems to be a windows machine which does not respond to ICMP" + notify-send "$host is now reachable" "and seems to be a windows machine" -u normal -t 30000 -a conn + echo "-----------------------------------------------------" + elif [[ $fping = "$host" ]] && [[ -n $(echo $p135 | grep "Successful connections: 1") ]];then + echo "-------------------Availability----------------------" + echo "note: this seems to be a windows machine which does respond to ICMP" + fping -e $host + notify-send "$host is now reachable" "and seems to be a windows machine" -u normal -t 30000 -a conn + echo "-----------------------------------------------------" + else + while [[ "$(fping $only -m -q -u $host)" == "$host" ]]; do : + done + echo "-------------------Availability----------------------" + fping -e $host + if [[ ! $oscheck == false ]];then + rescue=$(nping $only -q1 -c1 -p22,222 $host) + fi if [[ -n $(echo $rescue | grep "Successful connections: 1") ]];then echo "note: this seems to be a linux machine" + notify-send "$host is now reachable" "and seems to be in a linux system" -u normal -t 30000 -a conn elif [[ -n $(echo $rescue | grep "Successful connections: 2") ]];then echo "note: this machine seems to be in the rescue system" + notify-send "$host is now reachable" "and seems to be in the rescue system" -u normal -t 30000 -a conn elif [[ -n $(echo $p135 | grep "Successful connections: 1") ]] || [[ -n $(echo $p3389 | grep "Successful connections: 1") ]];then echo "note: this machine seems to be booted into windows" + notify-send "$host is now reachable" "and seems to be booted into windows" -u normal -t 30000 -a conn + else + notify-send "$host is now reachable" -u normal -t 30000 -a conn fi + echo "-----------------------------------------------------" + fi + else + echo "checking connection status for $host" + fping=$(fping $only -a $host) + if [[ ! $oscheck == false ]];then + p135=$(nping $only -q1 -c1 -p135 $host) + p3389=$(nping $only -q1 -c1 -p3389 $host) + fi + if [[ $fping != "$host" ]] && [[ -n $(echo $p135 | grep "Successful connections: 1") ]] || [[ $fping != "$host" ]] && [[ -n $(echo $p3389 | grep "Successful connections: 1") ]];then + echo "-------------------Availability----------------------" + echo "note: this seems to be a windows machine which does not respond to ICMP" + echo "-----------------------------------------------------" + elif [[ $fping != "$host" ]] && [[ -z $(echo $p135 | grep "Successful connections: 1") ]] || [[ $fping != "$host" ]] && [[ -z $(echo $p3389 | grep "Successful connections: 1") ]];then + echo "-------------------Availability----------------------" + echo "$host is not reachable" + echo "-----------------------------------------------------" + else + echo "-------------------Availability----------------------" + fping $only -e $host + if [[ ! $oscheck == false ]];then + rescue=$(nping $only -q1 -c1 -p22,222 $host) + if [[ -n $(echo $rescue | grep "Successful connections: 1") ]];then + echo "note: this seems to be a linux machine" + elif [[ -n $(echo $rescue | grep "Successful connections: 2") ]];then + echo "note: this machine seems to be in the rescue system" + elif [[ -n $(echo $p135 | grep "Successful connections: 1") ]] || [[ -n $(echo $p3389 | grep "Successful connections: 1") ]];then + echo "note: this machine seems to be booted into windows" + fi + fi + echo "-----------------------------------------------------" fi - echo "-----------------------------------------------------" fi if [[ ! $doportscan == false ]];then if [[ $doportscan == true ]];then @@ -168,7 +211,7 @@ function main { echo "" fping $only -c 4 $host echo "------------------------------------------------" - exit + echo "" else echo "" fi From 236930bc73bad1aa6c176765e6c07f7058a5b124 Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 28 Nov 2021 19:19:39 +0100 Subject: [PATCH 09/13] fix issue with unrecognized arguments --- conn.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/conn.sh b/conn.sh index 3601249..f62c16f 100755 --- a/conn.sh +++ b/conn.sh @@ -76,6 +76,10 @@ function get_args { # echo "the given argument \""$arg"\" is not known" # done # fi + + #quick fix to prevent nslookups interactive mode being triggered by wrong arguments + #some other places in the code have also gotten a leading space to prevent similar issues + input=$(echo "$input" | tr -d "-") } function set_argvars { @@ -104,7 +108,7 @@ function set_argvars { function validate { for arg in $@; do - if $(ip route show "$arg" 2&> /dev/null);then + if $(ip route show " $arg" 2&> /dev/null);then hosts="$hosts $arg" elif $(nslookup "$arg" > /dev/null);then hosts="$hosts $arg" From e68d8d52b27d3c0df2e717bf5e5b079e984f1d45 Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 30 Nov 2021 13:35:43 +0100 Subject: [PATCH 10/13] make simplified output prettier --- conn.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/conn.sh b/conn.sh index f62c16f..0c71697 100755 --- a/conn.sh +++ b/conn.sh @@ -122,11 +122,22 @@ function main { if [[ $simpleoutput == true ]] && [[ -n $hosts ]];then echo "-------------------Availability----------------------" fping $only -e $@ - quickport=$(nping $only -c1 -p22,222,3389,135 $@ | grep -e "completed") - if [[ -n $quickport ]];then - echo "" - echo "$quickport" - fi + echo "" + for host in $@;do + linuxping=$(nping $only -c1 -p22,222 "$host") + if [[ -n $(echo "$linuxping" | grep -e "Successful connections: 1") ]];then + echo "$host seems to be booted into a Linux system" + elif [[ -n $(echo "$linuxping" | grep -e "Successful connections: 2") ]];then + echo "$host seems to be booted into the rescue system" + fi + winping135=$(nping $only -c1 -p135 "$host") + winping3389=$(nping $only -c1 -p3389 "$host") + if [[ -n $(echo "$winping135" | grep -e "Successful connections: 1") ]] && [[ -n $(echo "$winping3389" | grep -e "Successful connections: 1") ]];then + echo "$host seems to be booted into Windows" + elif [[ -z $(fping $only -a $host) ]] && [[ -n $(echo "$winping3389" | grep -e "Successful connections: 1") ]];then + echo "$host seems to be booted into (desktop) Windows" + fi + done echo "-----------------------------------------------------" else for host in $hosts;do From bce9576c2dbed3a2cef60b46e7bfb032fac0a9ea Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 4 Dec 2021 00:17:18 +0100 Subject: [PATCH 11/13] optimize validate function --- conn.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conn.sh b/conn.sh index 0c71697..cac5a67 100755 --- a/conn.sh +++ b/conn.sh @@ -108,9 +108,9 @@ function set_argvars { function validate { for arg in $@; do - if $(ip route show " $arg" 2&> /dev/null);then + if ip route show " $arg" 2&> /dev/null;then hosts="$hosts $arg" - elif $(nslookup "$arg" > /dev/null);then + elif nslookup "$arg" > /dev/null;then hosts="$hosts $arg" else echo "invalid input: $arg" From 190a85326c1a6b6eea75353dbe688043e078c705 Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 5 Dec 2021 13:34:44 +0100 Subject: [PATCH 12/13] cleanup code and enable updater for merge --- conn.sh | 62 +++++++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/conn.sh b/conn.sh index cac5a67..e1832a2 100755 --- a/conn.sh +++ b/conn.sh @@ -17,19 +17,6 @@ arguments: -f / --fast disable os check -s / --simple simplify output" -show_notfound="[error] argument not found - -available arguments: - -h / --help show help page (this) - -6 / --force-ipv6 force ipv6 portscanning (also forces portscanning) - -4 / --force-ipv4 force ipv4 portscanning (also forces portscanning) - -y / --yes portscan without asking - -n / --no dont portscan - -w / --wait wait for active connection - -u / --update update the script - -f / --fast disable os check - -s / --simple simplify output" - function check_update { if [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) != $(md5sum $0 | cut -c -32) ]] && [[ -z $1 ]] || [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) != $(md5sum $0 | cut -c -32) ]] && [[ $1 != "--update" ]] || [[ $(curl -s https://raw.githubusercontent.com/byReqz/conn/main/hash) != $(md5sum $0 | cut -c -32) ]] && [[ $1 != "-u" ]];then echo "#############################################" @@ -55,7 +42,7 @@ function run_update { } function prepare { - #check_update + check_update get_args "$@" set_argvars $args validate $input @@ -68,16 +55,7 @@ function get_args { input=$(echo "$input" | sed "s/$arg//g") done -# needs work -# argcheck=$(echo $input | grep -o -e " -* " | xargs) -# echo $argcheck -# if [[ -n "$argcheck" ]];then -# for arg in $argcheck; do -# echo "the given argument \""$arg"\" is not known" -# done -# fi - - #quick fix to prevent nslookups interactive mode being triggered by wrong arguments + #quick fix to prevent nslookups interactive mode being triggered by invalid arguments #some other places in the code have also gotten a leading space to prevent similar issues input=$(echo "$input" | tr -d "-") } @@ -122,22 +100,24 @@ function main { if [[ $simpleoutput == true ]] && [[ -n $hosts ]];then echo "-------------------Availability----------------------" fping $only -e $@ - echo "" - for host in $@;do - linuxping=$(nping $only -c1 -p22,222 "$host") - if [[ -n $(echo "$linuxping" | grep -e "Successful connections: 1") ]];then - echo "$host seems to be booted into a Linux system" - elif [[ -n $(echo "$linuxping" | grep -e "Successful connections: 2") ]];then - echo "$host seems to be booted into the rescue system" - fi - winping135=$(nping $only -c1 -p135 "$host") - winping3389=$(nping $only -c1 -p3389 "$host") - if [[ -n $(echo "$winping135" | grep -e "Successful connections: 1") ]] && [[ -n $(echo "$winping3389" | grep -e "Successful connections: 1") ]];then - echo "$host seems to be booted into Windows" - elif [[ -z $(fping $only -a $host) ]] && [[ -n $(echo "$winping3389" | grep -e "Successful connections: 1") ]];then - echo "$host seems to be booted into (desktop) Windows" - fi + if [[ $oscheck != "false" ]];then + echo "" + for host in $@;do + linuxping=$(nping $only -c1 -p22,222 "$host") + if [[ -n $(echo "$linuxping" | grep -e "Successful connections: 1") ]];then + echo "$host seems to be booted into a Linux system" + elif [[ -n $(echo "$linuxping" | grep -e "Successful connections: 2") ]];then + echo "$host seems to be booted into the rescue system" + fi + winping135=$(nping $only -c1 -p135 "$host") + winping3389=$(nping $only -c1 -p3389 "$host") + if [[ -n $(echo "$winping135" | grep -e "Successful connections: 1") ]] && [[ -n $(echo "$winping3389" | grep -e "Successful connections: 1") ]];then + echo "$host seems to be booted into Windows" + elif [[ -z $(fping $only -a $host) ]] && [[ -n $(echo "$winping3389" | grep -e "Successful connections: 1") ]];then + echo "$host seems to be booted into (desktop) Windows" + fi done + fi echo "-----------------------------------------------------" else for host in $hosts;do @@ -244,6 +224,6 @@ elif [[ "$1" == "-h" ]];then check_update echo "$show_help" else - #check_update + check_update echo "$show_help" -fi \ No newline at end of file +fi From d06b4c3ca0f582091cebb0d3037b078228e3e5df Mon Sep 17 00:00:00 2001 From: actions Date: Sun, 5 Dec 2021 12:35:27 +0000 Subject: [PATCH 13/13] updated hash after commit --- hash | 1 + 1 file changed, 1 insertion(+) create mode 100644 hash diff --git a/hash b/hash new file mode 100644 index 0000000..19233ee --- /dev/null +++ b/hash @@ -0,0 +1 @@ +0f91143820ae11bd353a4ff25dc8cca5