Gentoo Archives: gentoo-user

From: Mick <michaelkintzios@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] [OT] network discovery tools
Date: Thu, 26 May 2011 19:05:22
Message-Id: 201105262004.34740.michaelkintzios@gmail.com
In Reply to: Re: [gentoo-user] [OT] network discovery tools by Florian Philipp
1 On Thursday 26 May 2011 17:24:05 Florian Philipp wrote:
2 > Am 25.05.2011 21:45, schrieb Harry Putnam:
3 > > There must be a number of people who post here that have had to do
4 > > this problem.
5 > >
6 > > Discover the addresses of computers on a home network that have
7 > > connected by way of DHCP. For example: Several wireless connections.
8 > >
9 > > I've used static IPS for around 10 yrs, always seemed handier for
10 > > things like ssh between home lan computers.
11 > >
12 > > But recently started using DHCP for wireless connections. It must be
13 > > such a popular method for some reason.
14 > >
15 > > But when you do it that way, and say want to VNC or ssh or the like to
16 > > something connected by a dhcp serving WAP then how do you find the
17 > > address?
18 > >
19 > > That is, besides something like accessing the WAP and checking the IPs
20 > > connected to it.
21 > >
22 > > Is there some quick and sure way to discover any IPs on the home lan?
23 > >
24 > > Some kind of mapper tool?
25 >
26 > While I personally prefer a combined DHCP+DNS server like dnsmasq, you
27 > can also take a look at the whole Zeroconf/MDNS/Avahi/Bonjour stack.
28 >
29 > I'm not really sure if you can configure common devices and Linux PCs to
30 > use the DNS server for internet addresses and MDNS for local ones. In
31 > theory, it should be possible since you can distinguish them (local
32 > addresses should not be fully qualified _or_ have the domain .local).
33 >
34 > net-misc/mDNSResponder, sys-auth/nss-mdns and net-dns/avahi are probably
35 > good starting points.
36
37 netdiscover seems to do exactly what the OP asked for, although I have used
38 arping and a couple of scripts I found on the net and modified them.
39
40 The first looks like this:
41 =============================
42 #!/usr/bin/env bash
43
44 quit_on_found=0
45 packet_count=2
46 subnet=""
47 verbose="-q"
48
49 usage()
50 {
51 cat << EOF
52 find_ip 1.0 Robin Wood (dninja@×××××.com) (www.digininja.org)
53
54 Find used and unused IPs on a network you don't haven an IP address on
55
56 usage: $0 options
57
58 OPTIONS:
59 -h Show this message
60 -c <packet count> The number of ping packets to send, default 2
61 -s <subnet> First 3 parts of the subnet to test, default
62 192.168.0
63 -q Quit when found first free address, default keep
64 going
65 -v Verbose
66
67 EOF
68 }
69
70 have_arping=`which arping`
71
72 if [[ "$have_arping" == "" ]]
73 then
74 cat << EOF
75 usage: $0 options
76
77 You must have arping installed and in the current path for this scanner to
78 work
79 EOF
80 exit 1
81 fi
82
83 while getopts ":hvs:qc:" flag
84 do
85 case $flag in
86 h)
87 usage
88 exit 1
89 ;;
90 c)
91 packet_count=$OPTARG
92 ;;
93 q)
94 quit_on_found=1
95 ;;
96 s)
97 subnet=$OPTARG
98 ;;
99 v)
100 verbose=""
101 ;;
102 ?)
103 usage
104 exit 1
105 ;;
106 esac
107 done
108
109 if [[ "$subnet" == "" ]]
110 then
111 cat << EOF
112 usage: $0 options
113
114 You must provide a subnet
115 EOF
116 exit 1
117 fi
118
119 if [[ "$verbose" == "" ]]
120 then
121 if [[ $quit_on_found == 1 ]]
122 then
123 echo "Quiting when found a free address"
124 fi
125 echo "Testing subnet $subnet.0/24"
126 echo "Sending $packet_count packets per IP"
127 fi
128
129 for i in {1..254}
130 do
131 IP=$subnet.$i
132 arping $verbose -c $packet_count $IP
133 result=$?
134 if [[ $result == 0 ]]
135 then
136 echo "$IP Used"
137 else
138 echo "$IP Free"
139 if [[ $quit_on_found == 1 ]]
140 then
141 exit
142 fi
143 fi
144 done
145 =============================
146
147 Google for "find_ip.sh"
148
149 The other which I can't find at the moment prints out the MAC address of each
150 IP address that is in use. Alternatively, run the above script with the -v
151 option and then scroll back to look at the MAC addresses.
152
153 Of course, I was using this before I knew that netdiscover existed - thanks
154 for sharing!
155 --
156 Regards,
157 Mick

Attachments

File name MIME type
signature.asc application/pgp-signature