-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_ip.sh
executable file
·106 lines (92 loc) · 1.56 KB
/
find_ip.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
quit_on_found=0
packet_count=2
subnet=""
verbose="-q"
interface='wlp4s0'
usage()
{
cat << EOF
find_ip 1.0 Robin Wood ([email protected]) (www.digininja.org)
Find used and unused IPs on a network you don't haven an IP address on
usage: $0 options
OPTIONS:
-h Show this message
-c <packet count> The number of ping packets to send, default 2
-s <subnet> First 3 parts of the subnet to test, default 192.168.0
-q Quit when found first free address, default keep going
-v Verbose
-i <interface>
EOF
}
have_arping=`which arping`
if [[ "$have_arping" == "" ]]
then
cat << EOF
usage: $0 options
You must have arping installed and in the current path for this scanner to work
EOF
exit 1
fi
while getopts ":hvs:qc:i:" flag
do
case $flag in
h)
usage
exit 1
;;
c)
packet_count=$OPTARG
;;
q)
quit_on_found=1
;;
s)
subnet=$OPTARG
;;
v)
verbose=""
;;
i)
interface=$OPTARG
;;
?)
usage
exit 1
;;
esac
done
if [[ "$subnet" == "" ]]
then
cat << EOF
usage: $0 options
You must provide a subnet
EOF
exit 1
fi
if [[ "$verbose" == "" ]]
then
if [[ $quit_on_found == 1 ]]
then
echo "Quiting when found a free address"
fi
echo "Testing subnet $subnet.0/24"
echo "Sending $packet_count packets per IP"
fi
for i in {1..254}
#for i in {1..254}
do
IP=$subnet.$i
arping -I $interface $verbose -c $packet_count $IP
result=$?
if [[ $result == 0 ]]
then
echo "$IP Used"
else
echo "$IP Free"
if [[ $quit_on_found == 1 ]]
then
exit
fi
fi
done