Script examples

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 19:07, 17 December 2005 (edit)
62.255.64.4 (Talk)
(added signal level scripts)
← Previous diff
Revision as of 19:19, 17 December 2005 (edit) (undo)
62.255.64.4 (Talk)
(with bargraph example)
Next diff →
Line 76: Line 76:
==Signal strength== ==Signal strength==
===In client Mode=== ===In client Mode===
-If you are using the wrt in client mode and connecting it to another AP, you might need monitor the signal level that you are recieving at the client wrt. To do this we use the 'wl' command to access the details from the wireless driver.+If you are using the wrt in client mode and connecting it to another AP, you might want monitor the signal level that you are recieving at the client wrt. To do this we use the 'wl' command to access the details from the wireless driver.
wl rssi wl rssi
gives the signal strength in dB's and gives the signal strength in dB's and
wl noise wl noise
-gives the niose level. We are interested in the nsignal to noise figure and in monitoring it continuously, so we need a small script to do it.+gives the niose level.
 + 
 +We are interested in the signal to noise figure and in monitoring it continuously, so we need a small script to do it. I also decided that it would be usefull to display a small graph of the s/n figure. This is an ugly script as I had to optimise it to get it to work fast enough to be usefull on the slow wrt processors :( , but this does mean that it can easily just be cut and pasted into a telnet or ssh session onto the wrt as an ugly one-liner.
 + 
 + while true;do echo `wl rssi;wl noise`|awk '{print $3-$6}'|awk '{printf"Signal : "$1"\t";for(;j<$1;j++)printf"=";printf"\n"}';done
 + 
 +It will look a bit like this :-
 + 
 + Signal : 8 ========
 + Signal : 7 =======
 + Signal : 8 ========
 + Signal : 10 ==========
 + Signal : 9 =========
 + Signal : 11 ===========
 + 
 +To terminate, just press <ctrl> + c
 + 
===In AP mode=== ===In AP mode===
'''You are here: ''' '''[[Main Page]]'''/'''[[DD-WRT Docu (EN)]]'''/'''[[Script Examples]]''' '''You are here: ''' '''[[Main Page]]'''/'''[[DD-WRT Docu (EN)]]'''/'''[[Script Examples]]'''

Revision as of 19:19, 17 December 2005

Contents


Which IPs and hostnames are used for wireless clients?

Note: Only work if you get an IP from DHCP

 # mkdir -p /tmp/www
 while [ 1 ];
  do
  wl assoclist | awk '{print$2}' > /tmp/assocLIST
  # echo "<meta http-equiv="refresh" content="10"><b>Hostnames and IPs of WLAN clients</b> (last update: $(date))<p>"     > /tmp/www/wlan.html
  while read assocLINE
   do
     dumpleases | grep -i $assocLINE | awk '{print "Hostname: " $1, "MAC: " $2, "IP: " $3}'
   # echo "<br>";
        done < /tmp/assocLIST     # >> /tmp/www/wlan.html
  sleep 10;
done;

Output:

Hostname: tp MAC: 01:81:18:3d:49:5e IP: 192.168.2.101

You can change the order of "$1, $2, $3" or cut-out:

....awk '{print $1,$3}'

Output:

tp 192.168.2.101

if you want to show this in a browser remove the # and use: http://routerIP/user/wlan.html

To booting on startup see Startup Scripts

How can I protect this file? I want to allow showing this only if you are logged in the web interface! Please write it here, thanks


Keep ISP from disconnecting due to lack of traffic

Some Internet Service Providers will drop the connection if there is no traffic for some period of time (Idle Time-Out). With these script you can prevent this.

 while [ 1 ];
 do
 ping -c 5 www.example.com > /dev/null    # ping 5 packets
 sleep 300;                               # wait 5 minutes
 done;

If this does not work (providers ignores ICMP packets as traffic) use:

 while [ 1 ];
 do
 wget http://www.example.com/ -O /tmp/index -q   # download index file
 sleep 300;                                      # wait 5 minutes
 done;

How many connections are open for each IP?

For each active IP on the local network (assumed to be a 192.168.x.0 network below), this prints out the number of connections that this IP has open to hosts on the Internet. "Connections" includes both TCP and UDP - while there are no "UDP connections", Linux maintains NAT-related information about UDP traffic which is similar to that for TCP.

This is handy for finding that person in your LAN whose P2P software opens many hundreds of connections, making the network slow for everybody.

sed -n 's%.* src=\(192.168.[0-9.]*\).*%\1%p' /proc/net/ip_conntrack | sort | uniq -c

this is great one! is it possible to display this in main status front page? how to see what source/dest ports are most connected? so we can examine if there's certain virus/worm spreading...

Signal strength

In client Mode

If you are using the wrt in client mode and connecting it to another AP, you might want monitor the signal level that you are recieving at the client wrt. To do this we use the 'wl' command to access the details from the wireless driver.

wl rssi

gives the signal strength in dB's and

wl noise

gives the niose level.

We are interested in the signal to noise figure and in monitoring it continuously, so we need a small script to do it. I also decided that it would be usefull to display a small graph of the s/n figure. This is an ugly script as I had to optimise it to get it to work fast enough to be usefull on the slow wrt processors :( , but this does mean that it can easily just be cut and pasted into a telnet or ssh session onto the wrt as an ugly one-liner.

while true;do echo `wl rssi;wl noise`|awk '{print $3-$6}'|awk '{printf"Signal  :  "$1"\t";for(;j<$1;j++)printf"=";printf"\n"}';done

It will look a bit like this :-

Signal  :  8    ========
Signal  :  7    =======
Signal  :  8    ========
Signal  :  10   ==========
Signal  :  9    =========
Signal  :  11   ===========

To terminate, just press <ctrl> + c

In AP mode

You are here: Main Page/DD-WRT Docu (EN)/Script Examples