forked from branchnetconsulting/wazuh-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tprobe
34 lines (30 loc) · 1.37 KB
/
tprobe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
DBG=1;
function tprobe() {
if [ "$DBG" == "1" ]; then echo "Preparing to probe $1 on port $2..."; fi
if [[ `echo $1 | grep -P "^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"` ]]; then
if [ "$DBG" == "1" ]; then echo "$1 appears to be an IP number."; fi
tpr_ip=$1
else
if [ "$DBG" == "1" ]; then echo "Looking up IP for host $1..."; fi
tpr_ip=`getent ahostsv4 $1 | awk '{ print $1 }' | head -n1`
fi
if [ "$tpr_ip" == "" ]; then
if [ "$DBG" == "1" ]; then echo "*** Failed to find IP for $1."; fi
exit 0
fi
if [ "$DBG" == "1" ]; then echo "Probing $tpr_ip:$2..."; fi
echo > /dev/tcp/$tpr_ip/$2 &
sleep 2
if [[ `ps auxw | awk '{print $2}' | egrep "^$!"` ]]; then
if [ "$DBG" == "1" ]; then echo "*** Failed to get response from $1 on tcp/$2."; fi
kill $!
exit 0
fi
if [ "$DBG" == "1" ]; then echo "Success!"; fi
}
# example call
tprobe www.google.com 443
# if the above probe fails execution of this script stops immediately and nothing here or below will run.
# another example call
tprobe 8.8.4.4 443