-
Notifications
You must be signed in to change notification settings - Fork 0
/
knock.sh
executable file
·54 lines (42 loc) · 935 Bytes
/
knock.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
IFS=$'\n'
NMAP=$(which nmap)
NC=$(which nc)
#trap '' TERM INT
function usage () {
echo "Knock a host using netcat or nmap"
echo "Usage: `basename $0` -h host -s seq"
echo "-h the host to be knocked"
echo "-s comma separated unlocking sequence"
exit 0
}
h_specified=0
# Parse command-line arguments.
while getopts ":h:s:" opt
do
case $opt in
h ) h_specified=1
h=$OPTARG ;;
s ) s_specified=1
s=$OPTARG ;;
\?) usage ;;
esac
done
if [[ $h_specified -eq 0 ]] || [[ $s_specified -eq 0 ]]
then
usage
fi
seq=($(echo "$s" | tr ',' '\n'))
echo "$(basename $0) started"
if [[ ! $NMAP && ! $NC ]]; then
echo "fatal: neither nmap nor netcat are available on this system";
fi
for i in "${!seq[@]}"; do
if [ $NMAP ]; then
$NMAP -Pn --host_timeout 201 --max-retries 0 -p ${seq[i]} $h
else
$NC -q1 -z $h ${seq[i]} &
fi;
sleep 1
done
echo "$(basename $0) done!"