mirror of
https://github.com/byReqz/conn.git
synced 2024-11-24 17:54:55 +00:00
Compare commits
1 Commits
0dbd251ae0
...
d68f3471f0
Author | SHA1 | Date | |
---|---|---|---|
|
d68f3471f0 |
147
conn.sh
147
conn.sh
@ -56,9 +56,8 @@ function run_update {
|
|||||||
|
|
||||||
function prepare {
|
function prepare {
|
||||||
#check_update
|
#check_update
|
||||||
get_args "$@"
|
get_args $@
|
||||||
set_argvars $args
|
set_argvars $args
|
||||||
validate $input
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_args {
|
function get_args {
|
||||||
@ -76,157 +75,21 @@ function get_args {
|
|||||||
# echo "the given argument \""$arg"\" is not known"
|
# echo "the given argument \""$arg"\" is not known"
|
||||||
# done
|
# done
|
||||||
# fi
|
# 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 {
|
function set_argvars {
|
||||||
if [[ $@ =~ -6 ]] || [[ $@ =~ --force-ipv6 ]];then
|
if [[ $@ =~ -6 ]] || [[ $@ =~ --force-ipv6 ]];then
|
||||||
only="-6"
|
only6=true
|
||||||
fi
|
fi
|
||||||
if [[ $@ =~ -4 ]] || [[ $@ =~ --force-ipv4 ]];then
|
|
||||||
only="-4"
|
|
||||||
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 {
|
function main {
|
||||||
if [[ $simpleoutput == true ]] && [[ -n $hosts ]];then
|
true
|
||||||
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
|
|
||||||
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
|
|
||||||
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
|
|
||||||
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 "------------------------------------------------"
|
|
||||||
echo ""
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -n $1 ]];then
|
if [[ -n $1 ]];then
|
||||||
prepare "$@"
|
prepare $@
|
||||||
main "$hosts"
|
main "$input"
|
||||||
elif [[ "$1" == "-u" ]];then
|
elif [[ "$1" == "-u" ]];then
|
||||||
run_update
|
run_update
|
||||||
elif [[ "$1" == "-h" ]];then
|
elif [[ "$1" == "-h" ]];then
|
||||||
|
Loading…
Reference in New Issue
Block a user