[Script] Detect machines on LAN & adjust Deluge limits

Suggest, post, or discuss plugins for Deluge

[Script] Detect machines on LAN & adjust Deluge limits

Postby lebrun » Tue Jan 10, 2012 8:44 pm

Since I share my internet connection with other people I started using Deluge's bandwidth scheduler plugin to avoid hogging the connections (and avoid conflicts)

I set Deluge max to 60KBps, and on the evening hours it goes down to 40KBps.

But during the day, even this seemed wasteful if no one was home. Increasing the max (or setting it to unlimited) would make the connection useless for anyone working from home (and yes, sometimes that includes me)

So I made a small script to be run via cron say, every 5 minutes. It uses smbtree to count the number of Windows machines on the network, excluding the current host. When no other machine is found, deluge is set for a higher max download limit, and when other machines are detected, it reverts deluge to more modest settings.

Here is the code, which is also hosted at: https://github.com/acarroz/autobw


Code: Select all
#!/bin/bash

logfile=$(echo "$0.log" | sed "s/.sh//g")

maxdownspeed="90.0"
maxupspeed="30.0"

regdownspeed="60.0"
regupspeed="15.0"

wincount=$(smbtree -S -N -b | grep '\\\\' | grep -v "`hostname`" | wc -l)
currdownspeed=$(deluge-console "config max_download_speed" | sed 's/ max_download_speed: //g')
now=$(date +"%F %T")

if [ $wincount -gt 0 ]; then
if [ $currdownspeed != $regdownspeed ]; then
deluge-console "config --set max_download_speed $regdownspeed"
    deluge-console "config --set max_upload_speed $regupspeed"

    echo "$now *REG* $wincount hosts found" >> $logfile
  fi
else
if [ $currdownspeed != $maxdownspeed ]; then
deluge-console "config --set max_download_speed $maxdownspeed"
    deluge-console "config --set max_upload_speed $maxupspeed"

    echo "$now *MAX* $wincount hosts found" >> $logfile
  fi
fi



The script will only detect Windows (or Samba) hosts, but for my particular situation, I can live with that.
lebrun
New User
New User
 
Posts: 3
Joined: Tue Jan 10, 2012 7:41 pm

Re: [Script] Detect machines on LAN & adjust Deluge limits

Postby Cas » Wed Jan 11, 2012 12:36 am

Thanks for this. Moved to the Plugins forum as its the most relevant place.
Cas
Developer
Developer
 
Posts: 2264
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: [Script] Detect machines on LAN & adjust Deluge limits

Postby CSB » Wed Jan 11, 2012 5:18 pm

Very interesting idea, a good solution for those who can't or don't want to run QoS, or manually manage the box (or allow others to) unfortunately it's no good for looking for things like set-top boxes, or if the people you share your connection with are in the habit of leaving their computers on.

I probably would have used arp to find MACs, since I'm not a Windows user.
CSB
Leecher
Leecher
 
Posts: 66
Joined: Fri Dec 03, 2010 1:55 am

Re: [Script] Detect machines on LAN & adjust Deluge limits

Postby lebrun » Wed Jan 11, 2012 7:26 pm

I'm not a Windows user either (at home) but the other guys I share the apartment with are. Would arp work without root (or sudo) ? The other commands I researched required root, and I really don't want to give that kind of permissions to the users this runs under.
lebrun
New User
New User
 
Posts: 3
Joined: Tue Jan 10, 2012 7:41 pm

Re: [Script] Detect machines on LAN & adjust Deluge limits

Postby CSB » Thu Jan 12, 2012 8:06 am

On both my OS X and Ubuntu machines, arp works under my user accounts.

You'd probably want to use arp-scan, though, which does require to be run as root, but let's not forget about setuid!
CSB
Leecher
Leecher
 
Posts: 66
Joined: Fri Dec 03, 2010 1:55 am

Re: [Script] Detect machines on LAN & adjust Deluge limits

Postby johnnyg » Thu Jan 12, 2012 12:20 pm

Most routers' status page lists which clients are connected; you could write a script to scrape that and adjust deluge accordingly although I think at this point configuring QoS is probably simpler.
johnnyg
Top Bloke
Top Bloke
 
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: [Script] Detect machines on LAN & adjust Deluge limits

Postby Cas » Thu Jan 12, 2012 12:39 pm

lebrun wrote: The other commands I researched required root, and I really don't want to give that kind of permissions to the users this runs under.
You can give a user access to a root only command by adding the user and command to the sudoers file.

http://www.cyberciti.biz/tips/allow-a-n ... -root.html

johnnyg wrote:Most routers' status page lists which clients are connected;

Interesting idea but relies on a router's client list that is correct as I've found mine to either hold onto clients too long or just not see others. :)
Cas
Developer
Developer
 
Posts: 2264
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: [Script] Detect machines on LAN & adjust Deluge limits

Postby lebrun » Wed Jan 18, 2012 6:33 pm

I forgot about the sudoers options.I'd do some experiments over the weekend. Maybe I can add a new scanning mode to the script. Also I think a config file is necessary.
lebrun
New User
New User
 
Posts: 3
Joined: Tue Jan 10, 2012 7:41 pm


Return to Plugins

Who is online

Users browsing this forum: No registered users and 0 guests