1
0
mirror of https://github.com/byReqz/conn.git synced 2024-11-24 17:54:55 +00:00
conn/conn.sh

101 lines
3.2 KiB
Bash
Raw Normal View History

2021-11-27 23:14:38 +00:00
#!/bin/bash
# license: gpl-3
show_help="conn: a quick and dirty server availability check
usage:
"$0" <args> [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
2021-11-28 00:26:31 +00:00
-s / --simple simplify output"
2021-11-27 23:14:38 +00:00
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"
2021-11-28 00:26:31 +00:00
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
}
2021-11-27 23:14:38 +00:00
function prepare {
2021-11-28 00:26:31 +00:00
#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
2021-11-27 23:14:38 +00:00
}
function main {
2021-11-28 00:26:31 +00:00
true
2021-11-27 23:14:38 +00:00
}
if [[ -n $1 ]];then
2021-11-28 00:26:31 +00:00
prepare $@
main "$input"
elif [[ "$1" == "-u" ]];then
run_update
elif [[ "$1" == "-h" ]];then
check_update
echo "$show_help"
2021-11-27 23:14:38 +00:00
else
2021-11-28 00:26:31 +00:00
#check_update
2021-11-27 23:14:38 +00:00
echo "$show_help"
fi