View Single Post
Posts: 5 | Thanked: 3 times | Joined on Jan 2010 @ Isle of Man
#49
Just a couple of other points

1) phonet is interesting, but I am not entirely sure if it is the best device to check for activity. In my experience it handles packets even when there is no connection in place. It may be that it is better to look at something like gprs0 (or whatever device is created when you are connected) as that will definitely relate to genuine traffic.

2) Using ifconfig is ok, but it is probably slightly more demanding than it needs to be. You can get the same result from the file /proc/net/dev, using something like

c=`grep wlan0 /proc/net/dev | awk '{ print $10 }'`

One of the joys of this option is that if you want to look for something like gprs devices it doesn't matter if they don't exist as you won't get an error.

3) The original script attempted to disconnect even if there was no current connection. I would consequently suggest that you could find out how you are currently connected by doing this ...

connection=`tail -1 /proc/net/route | cut -f1`

This would set the variable connection to be 'wlan0' or 'gprs0' or whatever you are using, or 'Iface' if you aren't connected. You could use this information to only look at the live connection for new packets. I am assuming in writing this that only one interface will be active at a time, so if you use something like 'openvpn' you would have an issue. Having said that products like openvpn tend to send regular packets anyway so you wouldn't be able to close your connection very easily.

Hopefully this information will be of help?

Last edited by farnwomt; 2010-01-28 at 16:40.
 

The Following 2 Users Say Thank You to farnwomt For This Useful Post: