1 AUTHOR: Eloi Primaux eloi AT bliscat dot org
5 LICENSE: GNU Free Documentation License Version 2
7 SYNOPSIS: Very basic network recognition using MAC address
10 https://www.harasdebondereau.com/bliscat/hints/network-recognition/network-recognition-0.0.2.tar.bz2
13 This hint explains how to make a very basic automatic network recognition
16 http://www.linuxfromscratch.org/hints/downloads/files/ATTACHMENTS/network-recognition/network-recognition-0.0.2.tar.bz2
20 - A working LFS-6.2 system or newer with wireless capabilities
21 - Almost two networks services like ipv4-static/dhcpcd installed
25 0) Requirement and Optional tools
26 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 Well, we will need the arpdiscover tool which comes from the arptools package.
29 The ArpTools package provides arpdiscover, arpfool and the so called arpflush.
30 You should only install the arpdiscover program, the others are used for network
33 The ArpTools package requires libnet and libpcap
36 ~~~~~~~~~~~~~~~~~~~~~~
38 http://ovh.dl.sourceforge.net/sourceforge/libpcap/libpcap-0.8.1.tar.gz
40 install it with these commands:
41 ./configure --prefix=/usr &&
45 0.2) libnet >= 1.1.3-RC-01
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~
48 http://www.packetfactory.net/libnet/dist/libnet-1.1.3-RC-01.tar.gz
50 install it with these commands:
51 ./configure --prefix=/usr &&
55 0.3) ArpTools >= 1.0.2 'The core'
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58 http://freshmeat.net/redir/arptools/63568/url_tgz/arptools-1.0.2.tar.gz
60 install it with these commands:
61 ./configure --prefix=/usr &&
65 0.3) NetDiscover >= 0.3-beta6
66 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 you can download it from:
68 http://nixgeneration.com/~jaime/netdiscover/releases/netdiscover-0.3-beta6.tar.gz
71 ./configure --prefix=/usr &&
77 you can download it from:
78 http://0pointer.de/lennart/projects/ifplugd/ifplugd-0.28.tar.gz
80 http://launchpadlibrarian.net/6580436/ifplugd_0.28-2.3ubuntu1.diff.gz
83 in the package directory, run this command to really apply the patch:
84 gunzip ../ifplugd_0.28-2.3ubuntu1.diff
85 patch -Np1 -i ../ifplugd_0.28-2.3ubuntu1.diff
86 patch -Np1 -i debian/patches/01_fix_ftbfs_feisty.dpatch
88 ifplugd install it's configuration in /etc/ifplugd, i don't like this
90 sed 's,/ifplugd/ifplugd.action,/sysconfig/ifplugd/ifplugd.action,' -i src/ifplugd.c
91 sed 's,ifplugd/ifplugd.conf,/sysconfig/ifplugd/ifplugd.conf,' -i conf/ifplugd.init.in
93 now compile and install:
94 ./configure --prefix=/usr --sysconfdir=/etc &&
103 now we have a tool which can discover MAC address
105 1.1) Install Files and Directories (this is only a proposal)
106 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 Extract network-recognition-0.0.1.tar.bz2 and in the extracted directory and run the
112 install -dv -m 700 /etc/sysconfig/network.d
113 install -dv /etc/sysconfig/network-recognition
114 install -dv /usr/share/doc/network-recognition
116 install -m 744 netdevices-example /etc/sysconfig/network.d/netdevice.example
117 install -v -m644 network-recognition-conf /etc/sysconfig/network-recognition/network-recognition.conf
118 install -v -m750 network-recognition-script /usr/sbin/network-recognition
121 OPTION 2: same as above but in a script
122 ./install.sh (if present ;)
127 The network-recognition script use a netdevices file in which are stored
128 network names, with specific ip and mac address of knowned permanent network
129 devices such as routers. The script call arpdiscover to check if that device is
130 present, if the device is present the script exit the loop and returns the name
131 of the network it successfully recognized.
133 This first discovering method is really slow (10-15 sec per scan), it uses
134 arpdiscover, the second method is faster and uses netdiscover.
136 2) IP service integration
137 ~~~~~~~~~~~~~~~~~~~~~~~~~
138 In the case of wpa-service you simply edit the wpa-actions file and replace
139 the function get_ssid by :
142 if [ "$EVENT" == "CONNECTED" ]; then
143 RET=`network-discover $IFACE`
144 echo $RET > "$WPA_ACCESS_DIR/$IFACE.ssid"
146 if [ -e "$WPA_ACCESS_DIR" ]; then
147 RET=$(cat "$WPA_ACCESS_DIR/$IFACE.ssid")
152 In the case of ifplugd you can modify the ifplugd.action file like this:
154 BEGIN of ifplugd.action
156 . /etc/sysconfig/network-recognition/network-recognition.conf
158 if [ -z "$1" ] || [ -z "$2" ] ; then
159 echo "Wrong arguments" > /dev/stderr
163 function reload_avahi {
166 if [ "$RET" == "0" ]; then
172 [ "$2" == "up" ] && EVENT="CONNECTED"
173 [ "$2" == "down" ] && EVENT="DISCONNECTED"
176 if [ "$EVENT" == "CONNECTED" ]; then
177 RET=`network-recognition $IFACE` &> /dev/null
178 echo $RET > "/tmp/$IFACE.ssid"
180 if [ -e "/tmp/$IFACE.ssid" ]; then
181 RET=$(cat "/tmp/$IFACE.ssid")
187 if [ "$EVENT" == "CONNECTED" ]; then
190 # configure network, signal DHCP client, etc.
191 # If special networks definition exist, use it
192 if [ -f "$NETWORKDIR/$SSID" ]; then
193 IFCONFIG="$NETWORKDIR/$SSID"
196 $SERVICESDIR/$SERVICE $IFACE up
198 IFCONFIG="$NETWORKDIR/AUTO"
201 $SERVICESDIR/$SERVICE $IFACE up
204 # reload the Avahi daemon if it runs
210 if [ "$EVENT" == "DISCONNECTED" ]; then
211 # remove network configuration, if needed
213 if [ "x$RET" != "x" ]; then
214 # this is false when there is nothing known around
215 # and when the system is disabling the service
217 # configure network, signal DHCP client, etc.
218 # If special networks definition exist, use it
219 if [ -f "$NETWORKDIR/$SSID" ]; then
220 IFCONFIG="$NETWORKDIR/$SSID"
223 $SERVICESDIR/$SERVICE $IFACE down
225 IFCONFIG="$NETWORKDIR/AUTO"
228 $SERVICESDIR/$SERVICE $IFACE down
232 # reload the Avahi daemon if it runs
236 END of ifplugd.action
238 remember to add your computer network device to /etc/sysconfig/ifplugd/ifplugd.conf
243 Script configuration go in the
244 /etc/sysconfig/network-recognition/network-recognition.conf file
247 2.1) Network configurations (IP):
248 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250 In fact i strongly use the wpa-service ipconf methods, that why i use the same
251 configuration files for networks.
253 this part comes from the wpa-service hint:
255 you can set up your network according to it's network_name (eg SSID), this means
256 that if the SSID "DHCP_network" manage ip via a dhcp server, wpa-service will
257 use the SSID file descriptor to set up you network when connecting to the SSID
260 Those ssid descriptors are named with the name of the SSID they describe,
261 and took place in the /etc/sysconfig/network.d directory.
263 The "AzErTy" SSID descriptor will be /etc/sysconfig/network.d/AzeRtY
265 2.1.1) SSID descriptor syntax:
266 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268 An SSID descriptor is a regular network configuration file as used in LFS BOOK.
269 it means that if SSID "IPV4" use ipv4-static, the the descriptor "IPV4" will be
271 cat > /etc/sysconfig/network.d/IPV4 << "EOF"
277 BROADCAST=192.168.1.255
280 and if the "DHCP" SSID use dhcp :
282 cat > /etc/sysconfig/network.d/DHCP << "EOF"
287 # the '-o' prevent your interface being destroyed by dhcpcd
289 # Set PRINTIP="yes" to have the script print
290 # the DHCP assigned IP address
293 # Set PRINTALL="yes" to print the DHCP assigned values for
294 # IP, SM, DG, and 1st NS. This requires PRINTIP="yes".
298 for convenience, your ip manager will fall back to /etc/sysconfig/network.d/AUTO
299 when no SSID descriptor is available.
301 Then install a common/automatic network configuration:
304 cat > /etc/sysconfig/network.d/AUTO << "EOF"
309 # the '-o' prevent your interface being destroyed by dhcpcd
311 # Set PRINTIP="yes" to have the script print
312 # the DHCP assigned IP address
315 # Set PRINTALL="yes" to print the DHCP assigned values for
316 # IP, SM, DG, and 1st NS. This requires PRINTIP="yes".
320 3) The netdevice file (The network description)
321 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323 We've installed an example file in /etc/sysconfig/network.d
325 Now edit the newly created netdevices file:
326 Which should contains something similar to:
330 # ip of the permanent device
332 # mac address of the permanent device
333 mac=00:0F:B5:EE:88:8C
337 You will directly see that you can define more than one network and also more
338 than one permanent device by duplicating the network blocs
340 You can feed this file by running directly arpdiscover when you plug in a new
343 arpdiscover IP iterations computer_network_device
346 another usefull tool to do this would be netdiscover
350 4) Feeding our netdevices file
351 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352 The perfect tool: NetDiscover
358 it will show you everything connected to your network (and more)
362 2007 11 11 First release, first send to lfshint
363 2007 11 22 Second release added netdiscover method and some bugs fixed
364 + avahi-daemon reload in ifplugd.action
365 + a work around for bad promiscuous netcards mode