-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipScan.sh
75 lines (60 loc) · 1.95 KB
/
ipScan.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
###############################################
############## Simple IP Scanner ##############
############## Made by CodeShark ##############
############## Version - 1.2 ##############
###############################################
# Usage: ./ipScan.sh <ip-range>
# Example: ./ipScan.sh 10.2.1
function ctrl_c(){
echo -e "\n\n[*] Saliendo...\n"
tput cnorm
exit 1
}
trap ctrl_c INT
function init(){
echo
echo -e "\t\t###############################################"
echo -e "\t\t############## Simple IP Scanner ##############"
echo -e "\t\t############## Made by CodeShark ##############"
echo -e "\t\t############## Version - 1.2 ##############"
echo -e "\t\t###############################################"
}
function usage(){
echo -e "\n\t[+] Usage: ipScan.sh <ip-range> <options>"
echo -e "\n\t[+] Example: ipScan.sh 127.0.0"
echo -e "\n\t[+] Example: ipScan.sh 127.0.0 -p\t Scan open ports in the range\n"
}
function scanPort(){
ip_addr=$1
for port in $(seq 1 65535); do
timeout 1 bash -c "echo '' > /dev/tcp/$ip_addr/$port" &>/dev/null && echo -e "\n\tHost: $ip_addr \tPort: $port - OPEN" &
done; wait
echo
}
init
if [ $# -eq 0 ]; then
echo -e "\n[!] No ip range supplied"
usage
exit 1
else
ip_range=$1
if [[ $ip_range =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
tput civis
echo -e "\n[+] Scanning range: $ip_range.0/24\n"
for ip in $(seq 1 254); do
if [ "$#" -eq 2 ] && [ "$2" = "-p" ]; then
timeout 1 bash -c "ping -c 1 $ip_range.$ip" &>/dev/null && echo -e "\tHost: $ip_range.$ip - ACTIVE" && scanPort "$ip_range.$ip" &
else
timeout 1 bash -c "ping -c 1 $ip_range.$ip" &>/dev/null && echo -e "\tHost: $ip_range.$ip - ACTIVE" &
fi
done; wait
echo
tput cnorm
exit 0
else
echo -e "\n[!] Enter a valid range"
usage
exit 1
fi
fi