-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_kcportscan.sh
executable file
·43 lines (35 loc) · 1.02 KB
/
test_kcportscan.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
#!/bin/bash
NUM_LISTENERS=99
LISTEN_HOST=127.0.0.1
SCAN_BLOCK_PREFIX=28
SCAN_TIMEOUT=200
for i in `eval echo "{0..$NUM_LISTENERS}"`; do
ports[$i]="$((((RANDOM + RANDOM) % 63001) + 2000))"
done
echo -n "Listening on `expr $NUM_LISTENERS + 1` random ports on $LISTEN_HOST"
for port in ${ports[@]}; do
echo -n "...$port"
./kclisten $LISTEN_HOST:$port 1>/dev/null &
done
echo
echo "Starting kcportscan on $LISTEN_HOST/$SCAN_BLOCK_PREFIX..."
./kcportscan -4 $LISTEN_HOST/$SCAN_BLOCK_PREFIX -t $SCAN_TIMEOUT >&/tmp/kcportscan.log &
job_id=$!
echo -n "Waiting for kcportscan ($job_id) to finish..."
wait $job_id
echo
# Kill any remaining listeners
for job_id in `jobs -p`; do
kill $job_id && wait $job_id
done
echo -n "Determining whether kcportscan found all the random ports"
for port in ${ports[@]}; do
grep -q "$LISTEN_HOST:$port accepted " /tmp/kcportscan.log
if [[ $? != 0 ]]; then
echo "...FAILURE! Missed $LISTEN_HOST:$port"
exit 1
fi
echo -n "...$port"
done
echo "...SUCCESS!"
exit 0