Изменение скорости интернета в заданное время. К примеру: Двойная скорость ночью.
В скрипте поднятия /etc/ppp/ip-up
HOUR_START=0
HOUR_END=8
HOUR=`date +%H`
if [ ${HOUR} -gt ${HOUR_START} ] && [ ${HOUR} -lt ${HOUR_END} ];
then
SPEED=$[ ${SPEED} * 2 ]
if [$channel != "utk"]
then
UPSPEED=${UPSPEED}
else
UPSPEED=$[ ${UPSPEED} * 2 ]
fi
elif [ ${HOUR} == ${HOUR_START} ]
then
SPEED=$[ ${SPEED} * 2 ]
if [$channel != "utk"]
then
UPSPEED=${UPSPEED}
else
UPSPEED=$[ ${UPSPEED} * 2 ]
fi
else
SPEED=${SPEED}
UPSPEED=${UPSPEED}
fi
PHP скрипт для изменения скорости текущих впн соединений
$tc = '/sbin/tc';
$ip = '/sbin/ip';
$double = 0;
$half = 0;
if (!empty($argv[1]) && $argv[1] == 'double')
$double = 1;
if (!empty($argv[1]) && $argv[1] == 'half')
$half = 1;
exec($ip.' r | grep ppp | awk \'{print $3;}\' | tr "[:upper:]" "[:lower:]"', $ipr);
$devs = array();
for ($i=0;$i
{
if (!in_array(trim($ipr[$i]),$devs))
$devs[]=trim($ipr[$i]);
}
for ($i=0;$i
{
$speed='';
exec($tc.' class sh dev '.$devs[$i].' | awk \'{print $11;}\'',$speed);
if (!empty($speed[0]) && eregi('Kbit',$speed[0])) // if Kilobits
{
$new_speed = eregi_replace('Kbit','',$speed[0]);
if ($half == 1) $new_speed = $new_speed / 2;
if ($double == 1) $new_speed = $new_speed * 2;
}
elseif (!empty($speed[0]) && !eregi('Kbit',$speed[0])) // if bits
{
$new_speed = eregi_replace('bit','',$speed[0]);
if ($half == 1) $new_speed = $new_speed / 1000 / 2;
if ($double == 1) $new_speed = $new_speed / 1000 * 2;
}
if (!empty($speed[0]) && $new_speed > 0)
{
exec($tc.' qdisc del dev '.$devs[$i].' root handle 1: htb default 20 r2q 2');
exec($tc.' qdisc del dev '.$devs[$i].' handle ffff: ingress');
exec($tc.' qdisc add dev '.$devs[$i].' root handle 1: htb default 20 r2q 2');
exec($tc.' class add dev '.$devs[$i].' parent 1: classid 1:1 htb rate '.$new_speed.'kbit burst 4k');
exec($tc.' class add dev '.$devs[$i].' parent 1:1 classid 1:10 htb rate '.$new_speed.'kbit burst 4k prio 1');
exec($tc.' class add dev '.$devs[$i].' parent 1:1 classid 1:20 htb rate '.$new_speed.'kbit burst 4k prio 2');
exec($tc.' qdisc add dev '.$devs[$i].' parent 1:10 handle 10: sfq perturb 10 quantum 1500');
exec($tc.' qdisc add dev '.$devs[$i].' parent 1:20 handle 20: sfq perturb 10 quantum 1500');
exec($tc.' filter add dev '.$devs[$i].' parent 1:0 protocol ip prio 10 u32 match ip tos 0x10 0xff flowid 1:10');
exec($tc.' filter add dev '.$devs[$i].' parent 1:0 protocol ip prio 10 u32 match ip protocol 1 0xff flowid 1:10');
exec($tc.' filter add dev '.$devs[$i].' parent 1: protocol ip prio 10 u32 match ip protocol 6 0xff match u8 0x05 0x0f at 0 match u160x0000 0xffc0 at 2 match u8 0x10 0xff at 33 flowid 1:10');
exec($tc.' qdisc add dev '.$devs[$i].' handle ffff: ingress');
exec($tc.' filter add dev '.$devs[$i].' parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate '.$new_speed.'kbit burst 12k drop flowid :1');
}
}
?>
добавить в /etc/crontab для изменения скорости текущих соединений в заданное время
0 0 * * * php -f /etc/ppp/double.speed.php double 1 > /dev/null 2 > /dev/null
0 8 * * * php -f /etc/ppp/double.speed.php half 1 > /dev/null 2 > /dev/null
Ви маєте увійти під своїм обліковим записом