improve address selection
[homepass.git] / homepass.sh
blob49bfb408a2963eca9ed1aff2a697fafe87233e6e
1 #!/bin/sh
2 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin:/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin
4 max=5
5 relay_time="90"
7 mac_list="00:0D:67:15:2D:82
8 00:0D:67:15:D7:21
9 00:0D:67:15:D5:44
10 00:0D:67:15:D2:59
11 00:0D:67:15:D6:FD
12 4E:53:50:4F:4F:40
13 4E:53:50:4F:4F:41
14 4E:53:50:4F:4F:42
15 4E:53:50:4F:4F:43
16 4E:53:50:4F:4F:44
17 4E:53:50:4F:4F:45
18 4E:53:50:4F:4F:46
19 4E:53:50:4F:4F:47
20 4E:53:50:4F:4F:48
21 4E:53:50:4F:4F:49
22 4E:53:50:4F:4F:4A
23 4E:53:50:4F:4F:4B
24 4E:53:50:4F:4F:4C
25 4E:53:50:4F:4F:4D
26 4E:53:50:4F:4F:4E
27 4E:53:50:4F:4F:4F"
29 wifi="eth1"
30 wl_mac=$(nvram get wl0_hwaddr)
32 ctrl_c() {
33 echo "*** Interrupted ***"
34 cleanup
35 exit $?
38 spoof() {
39 echo "Spoofing ${wifi} to $1 for ${relay_time} seconds..."
40 ifconfig ${wifi} down
41 ifconfig ${wifi} hw ether $1
42 ifconfig ${wifi} up
43 wl radio on
45 sleep ${relay_time}
47 wl radio off
50 cleanup() {
51 echo "Restoring ${wifi} to ${wl_mac}"
52 ifconfig ${wifi} down
53 ifconfig ${wifi} hw ether ${wl_mac}
54 ifconfig ${wifi} up
56 wl radio off
58 return 0
61 trap ctrl_c SIGINT SIGTERM
63 sel=$(echo "$mac_list" | awk -v n=\"$max\" 'BEGIN{ srand(); } { a[i++]=$0 } END { while(j<$n) { r=int(rand()*i); if( r in a ) { print a[r]; delete a[r]; j++; } } }')
64 for i in $sel
66 spoof "$i"
67 done
69 cleanup