forked from rahulkadavil/pentest-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portscan-nc.sh
executable file
·53 lines (44 loc) · 868 Bytes
/
portscan-nc.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
#!/bin/bash
function usage() {
echo "Usage: "$0" <ip> <port start> <port end> [<udp>]"
if [ -n "$1" ] ; then
echo "Error: "$1"!"
fi
exit
}
if [ $# -lt 3 ] || [ $# -gt 4 ] ; then
usage
fi
ip=$1
start=$2
end=$3
options="-n -v -z -w 1"
if [ $# -eq 4 ] ; then
options=$options" -u"
fi
if [ $end -lt $start ] ; then
tmp=$start
start=$end
end=$tmp
fi
i=0
test_found=0
test_limit=20
test_rate=10
for port in $(seq $start $end); do
if [ $i -lt $test_limit ] ; then
tmp=$(nc $options $ip $port 2>&1 | egrep "\) open|\] succeeded" &)
if [ -n "$tmp" ] ; then
echo $tmp
test_found=$[$test_found+1]
fi
if [ $test_found -ge $test_rate ] ; then
echo "Too much success, exiting!"
exit
fi
else
nc $options $ip $port 2>&1 | egrep "\) open|\] succeeded" &
fi
i=$[$i+1]
done
exit