1
0
mirror of https://github.com/byReqz/conn.git synced 2024-11-22 09:01:15 +00:00

rather big update

added multi-input (ipv4 and ipv6) detection, tweaked auto-detection regexes, added -4, tweaked syntax
This commit is contained in:
Nils 2021-01-16 23:15:46 +00:00 committed by GitHub
parent da4c4b57e5
commit f42ddf88d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

248
conn.sh
View File

@ -1,110 +1,140 @@
#!/bin/bash #!/bin/bash
while [ ! -n "$1" ]; do while [ ! -n "$1" ]; do
echo "Usage: $0 (options) <ip>" echo "Usage: $0 (options) <ip>"
echo "Options:" echo "Options:"
echo " -m/--multi -- test multiple ips / disable portscan" echo " -m/--multi -- test multiple ips / disable portscan"
echo " -h/--help -- show help" echo " -h/--help -- show help"
echo " -6/--force-ipv6 -- force ipv6 portscanning (also forces portscanning)" echo " -6/--force-ipv6 -- force ipv6 portscanning (also forces portscanning)"
echo " -y/--yes -- portscan without asking" echo " -4/--force-ipv4 -- force ipv4 portscanning (also forces portscanning)"
echo " -n/--no -- dont portscan" echo " -y/--yes -- portscan without asking"
echo " -p/--portscan -- same as -y" echo " -n/--no -- dont portscan"
echo " -w/--wait -- wait for active connection" echo " -p/--portscan -- same as -y"
exit echo " -w/--wait -- wait for active connection"
done exit
while [ ! -z "$1" ]; do done
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]];then while [ ! -z "$1" ]; do
echo "Usage: $0 (options) <ip> (y/n)" if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]];then
echo "Options:" echo "Usage: $0 (options) <ip> (y/n)"
echo " -m/--multi -- test multiple ips / disable portscan" echo "Options:"
echo " -h/--help -- show help" echo " -m/--multi -- test multiple ips / disable portscan"
echo " -6/--force-ipv6 -- force ipv6 portscanning (also forces portscanning)" echo " -h/--help -- show help"
echo " -y/--yes -- portscan without asking" echo " -6/--force-ipv6 -- force ipv6 portscanning (also forces portscanning)"
echo " -n/--no -- dont portscan" echo " -4/--force-ipv4 -- force ipv4 portscanning (also forces portscanning)"
echo " -p/--portscan -- same as -y" echo " -y/--yes -- portscan without asking"
echo " -w/--wait -- wait for active connection" echo " -n/--no -- dont portscan"
exit echo " -p/--portscan -- same as -y"
elif [[ $1 == "-m" ]] || [[ "$1" == "--multi" ]];then echo " -w/--wait -- wait for active connection"
echo "multi-ip mode, portscan disabled" exit
echo "-------------------Availability----------------------" elif [[ $1 == "-m" ]] || [[ "$1" == "--multi" ]];then
fping -e $@ echo "multi-ip mode, portscan disabled"
echo "-----------------------------------------------------" echo "-------------------Availability----------------------"
exit fping -m -e $@
elif [[ $1 == "-y" ]] || [[ $1 == "-p" ]] || [[ "$1" == "--portscan" ]] || [[ "$1" == "--yes" ]];then echo "-----------------------------------------------------"
echo "checking connection status for $2" exit
echo "-------------------Availability----------------------" elif [[ $1 == "-y" ]] || [[ $1 == "-p" ]] || [[ "$1" == "--portscan" ]] || [[ "$1" == "--yes" ]];then
fping -e $2 echo "checking connection status for $2"
echo "-----------------------------------------------------" echo "-------------------Availability----------------------"
echo "-------------------Portscan---------------------" fping -m -e $2
nmap -Pn $2 echo "-----------------------------------------------------"
fping -c 4 -A $2 echo "-------------------Portscan---------------------"
echo "------------------------------------------------" nmap -Pn $2
exit fping -m -c 4 -A $2
elif [[ $1 == "-n" ]] || [[ "$1" == "--no" ]];then echo "------------------------------------------------"
echo "checking connection status for $2" exit
echo "-------------------Availability----------------------" elif [[ $1 == "-n" ]] || [[ "$1" == "--no" ]];then
fping -e $2 echo "checking connection status for $2"
echo "-----------------------------------------------------" echo "-------------------Availability----------------------"
exit fping -m -e $2
elif [[ $1 == "-6" ]] || [[ "$1" == "--force-ipv6" ]];then echo "-----------------------------------------------------"
echo "-6 used, forcing IPv6 portscanning" exit
echo "checking connection status for $2" elif [[ $1 == "-6" ]] || [[ "$1" == "--force-ipv6" ]];then
echo "-------------------Availability----------------------" echo "-6 used, forcing IPv6 portscanning"
fping -6 -e $2 echo "checking connection status for $2"
echo "-----------------------------------------------------" echo "-------------------Availability----------------------"
echo "-------------------Portscan---------------------" fping -6 -e $2
nmap -Pn -6 $2 echo "-----------------------------------------------------"
fping -6 -c 4 -A $2 echo "-------------------Portscan---------------------"
echo "------------------------------------------------" nmap -Pn -6 $2
exit fping -6 -c 4 -A $2
elif [[ "$1" == "-w" ]] || [[ "$1" == "--wait" ]];then echo "------------------------------------------------"
echo "-w used, waiting for active connection" exit
echo "checking connection status for $2" elif [[ $1 == "-4" ]] || [[ "$1" == "--force-ipv4" ]];then
while [[ "$(fping -q -u $2)" == "$2" ]]; do : echo "-4 used, forcing IPv4 portscanning"
done echo "checking connection status for $2"
notify-send "$2 is now reachable" -u normal -t 8000 -a conn echo "-------------------Availability----------------------"
echo "-------------------Availability----------------------" fping -4 -e $2
fping -e $2 echo "-----------------------------------------------------"
echo "-----------------------------------------------------" echo "-------------------Portscan---------------------"
echo "portscan? (y/n) (default: y)" nmap -Pn $2
read portscan fping -6 -c 4 -A $2
if [[ "$portscan" = "y" ]] || [[ -z "$portscan" ]]; then echo "------------------------------------------------"
echo "-------------------Portscan---------------------" exit
nmap -Pn $2 elif [[ "$1" == "-w" ]] || [[ "$1" == "--wait" ]];then
fping -c 4 -A $2 echo "-w used, waiting for active connection"
echo "------------------------------------------------" echo "checking connection status for $2"
exit while [[ "$(fping -m -q -u $2)" == "$2" ]]; do :
elif [[ "$portscan" = "n" ]]; then done
exit notify-send "$2 is now reachable" -u normal -t 8000 -a conn
fi echo "-------------------Availability----------------------"
exit fping -m -e $2
#this checks if the ip is (not) ipv4 and then checks if it includes a : echo "-----------------------------------------------------"
elif [[ ! "$1" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] && [[ "$1" =~ [:] ]];then echo "portscan? (y/n) (default: y)"
echo "noticed IPv6 adress -> using -6" read portscan
echo "checking connection status for $1" if [[ "$portscan" = "y" ]] || [[ -z "$portscan" ]]; then
echo "-------------------Availability----------------------" echo "-------------------Portscan---------------------"
fping -6 -e $1 nmap -Pn $2
echo "-----------------------------------------------------" fping -m -c 4 -A $2
echo "-------------------Portscan---------------------" echo "------------------------------------------------"
nmap -Pn -6 $1 exit
fping -6 -c 4 -A $1 else
echo "------------------------------------------------" exit
exit fi
else exit
echo "checking connection status for $1" elif [[ ! "$1" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] && [[ "$1" =~ [:] ]] && [[ ! "$2" =~ [:] ]] && [[ -z "$3" ]];then
echo "-------------------Availability----------------------" echo "detected IPv6 adress -> using -6"
fping -e $1 echo "checking connection status for $1"
echo "-----------------------------------------------------" echo "-------------------Availability----------------------"
echo "portscan? (y/n) (default: y)" fping -6 -e $1
read portscan echo "-----------------------------------------------------"
if [[ "$portscan" = "y" ]] || [[ -z "$portscan" ]]; then echo "portscan? (y/n) (default: y)"
echo "-------------------Portscan---------------------" read portscan
nmap -Pn $1 if [[ "$portscan" = "y" ]] || [[ -z "$portscan" ]]; then
fping -c 4 -A $1 echo "-------------------Portscan---------------------"
echo "------------------------------------------------" nmap -Pn -6 $1
exit fping -6 -c 4 -A $1
elif [[ "$portscan" = "n" ]]; then echo "------------------------------------------------"
exit else
fi exit
fi fi
exit
elif [[ "$1" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] && [[ "$2" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] || [[ "$3" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] && [[ ! "$1" =~ [-] ]];then
echo "multi-ip input detected, portscan disabled"
echo "-------------------Availability----------------------"
fping -m -e $@
echo "-----------------------------------------------------"
exit
elif [[ ! "$1" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] && [[ ! "$2" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] && [[ "$1" =~ [:] ]] && [[ "$2" =~ [:] ]] || [[ ! "$3" =~ [0-9]{1,3}(\.[0-9]{1,3}){3} ]] && [[ ! "$1" =~ [-] ]];then
echo "multi-ipv6 input detected, portscan disabled"
echo "-------------------Availability----------------------"
fping -m -e -6 $@
echo "-----------------------------------------------------"
exit
else
echo "checking connection status for $1"
echo "-------------------Availability----------------------"
fping -m -e $1
echo "-----------------------------------------------------"
echo "portscan? (y/n) (default: y)"
read portscan
if [[ "$portscan" = "y" ]] || [[ -z "$portscan" ]]; then
echo "-------------------Portscan---------------------"
nmap -Pn $1
fping -m -c 4 -A $1
echo "------------------------------------------------"
exit
else
exit
fi
fi
done done