уже неделю ломаю голову над скриптом!!! динамического деления скорости по ip!!!
вот сам скрипт! нужно поправить синтас под версию 3.22!! он вобще под 4 - 5!!!
#Settings
################################################## ####
:local MaxRateDownload ("15000000");
:local MaxRateUpload ("15000000");
:local MaxRateDownloadNight ("20000000");
:local MaxRateUploadNight ("20000000");
:local ActiveThresholddown ("15000");
:local ActiveThresholdup ("15000");
:local usenighttime ("yes");
:local nighttimestart ("02:00");
:local nighttimestop ("08:00");
################################################## ####
#Internal Var
################################################## ####
:local z;
:local i;
:local ii;
:local userX;
:local timedelay (0);
:local startmin;
:local startsec;
:local stopmin;
:local stopsec;
:local scripttimedelay (0);
:local scriptstartmin;
:local scriptstartsec;
:local scriptstopmin;
:local scriptstopsec;
:local userscount ("0");
:local userstmp ("");
:local firstdowntmp ("");
:local firstuptmp ("");
:local twodowntmp ("");
:local twouptmp ("");
:local activedownuserstmp ("");
:local activeupuserstmp ("");
:local activedowncount ("0");
:local activeupcount ("0");
################################################## ####
################################################## ####
:set scriptstartmin ([: pick [/system clock get time] 3 5]);
:set scriptstartsec ([: pick [/system clock get time] 6 8]);
:if ($usenighttime = "yes") do={
:set nighttimestart ([: pick $nighttimestart 0 2] . [: pick $nighttimestart 3 5]);
:set nighttimestop ([: pick $nighttimestop 0 2] . [: pick $nighttimestop 3 5]);
:local currenthours ([: pick [/system clock get time] 0 2]);
:local currenttime ([: pick [/system clock get time] 0 2] . [: pick [/system clock get time] 3 5] );
:local acttime ("day");
:local starttime ("day");
:if ($currenthours < 10) do={ :set acttime ("night"); };
:if ( [: pick $nighttimestart 0 2] < 10) do={ :set starttime ("night"); };
:local night ("no");
:if ($starttime = "night") do={
:if ( $currenttime > $nighttimestart && $currenttime < $nighttimestop) do={ :set night ("yes"); };
};
:if ($starttime = "day") do={
:if ( $acttime = "day") do={
:if ( $currenttime >= $nighttimestart) do={ :set night ("yes"); };
};
:if ( $acttime = "night") do={
:if ( $currenttime < $nighttimestop ) do={ :set night ("yes"); };
};};
:if ($night = "yes") do={
:set MaxRateDownload ($MaxRateDownloadNight);
:set MaxRateUpload ($MaxRateUploadNight);
};
};
:set ActiveThresholddown ($ActiveThresholddown / 8);
:set ActiveThresholdup ($ActiveThresholdup / 8);
:foreach i in=[/ip firewall address-list find list="users"] do={ :set userX [/ip firewall address-list get $i address];
:set userscount ($userscount+1);
:set userstmp ($userstmp . $userX . ",");
};
:local users [:toarray $userstmp];
:set startmin ([: pick [/system clock get time] 3 5]);
:set startsec ([: pick [/system clock get time] 6 8]);
:global dcount ("1");
:for dcount from=1 to=$userscount step=1 do={
:set firstdowntmp ($firstdowntmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_down"] bytes] . ",");
:set firstuptmp ($firstuptmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_up"] bytes] . ",");
};
:set stopmin ([: pick [/system clock get time] 3 5]);
:set stopsec ([: pick [/system clock get time] 6 8]);
:global dcount ("1");
:for dcount from=1 to=$userscount step=1 do={
:set twodowntmp ($twodowntmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_down"] bytes] . ",");
:set twouptmp ($twouptmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_up"] bytes] . ",");
};
:if ( $stopmin > $startmin) do={
:set timedelay (($stopmin-$startmin) * 60);
};
:set timedelay (($timedelay+$stopsec)-$startsec);
:local firstdown [:toarray $firstdowntmp];
:local firstup [:toarray $firstuptmp];
:local twodown [:toarray $twodowntmp];
:local twoup [:toarray $twouptmp];
:global dcount ("1");
:for dcount from=1 to=$userscount step=1 do={
:if ( ($ActiveThresholddown * $timedelay) < ([:pick $twodown ($dcount-1)] - [:pick $firstdown ($dcount-1)]) ) do={
:set activedownuserstmp ($activedownuserstmp . [:pick $users ($dcount-1)] . ",");
:set activedowncount ($activedowncount+1);
};
:if ( ($ActiveThresholdup * $timedelay) < ([:pick $twoup ($dcount-1)] - [:pick $firstup ($dcount-1)]) ) do={
:set activeupuserstmp ($activeupuserstmp . [:pick $users ($dcount-1)] . ",");
:set activeupcount ($activeupcount+1);
};
};
:local activedownusers [:toarray $activedownuserstmp];
:local activeupusers [:toarray $activeupuserstmp];
:local maxlimitdown ("0");
:local maxlimitup ("0");
:if ( $activedowncount > 0 ) do={
:set maxlimitdown ($MaxRateDownload/$activedowncount);
:global dcount ("1");
:for dcount from=1 to=$activedowncount step=1 do={
:if ([/queue tree get [find name=[:pick $activedownusers ($dcount-1)] . "_down"] max-limit] != $maxlimitdown) do={
/queue tree set [/queue tree find name=[:pick $activedownusers ($dcount-1)] . "_down"] max-limit=$maxlimitdown; };
};
};
:if ( $activeupcount > 0 ) do={
:set maxlimitup ($MaxRateUpload/$activeupcount);
:global dcount ("1");
:for dcount from=1 to=$activeupcount step=1 do={
:if ([/queue tree get [find name=[:pick $activeupusers ($dcount-1)] . "_up"] max-limit] != $maxlimitup) do={
/queue tree set [/queue tree find name=[:pick $activeupusers ($dcount-1)] . "_up"] max-limit=$maxlimitup; };
};
};
:local kbsmaxdown ($MaxRateDownload/1000);
:local kbsmaxup ($MaxRateUpload /1000);
:if ( $maxlimitdown = 0 ) do={ :set maxlimitdown ($MaxRateDownload); };
:if ( $maxlimitup = 0 ) do={ :set maxlimitup ($MaxRateUpload); };
:local kbsmaxlimitdown ($maxlimitdown/1024);
:local kbsmaxlimitup ($maxlimitup/1024);
:set scriptstopmin ([: pick [/system clock get time] 3 5]);
:set scriptstopsec ([: pick [/system clock get time] 6 8]);
:if ( $scriptstopmin > $scriptstartmin) do={
:set scripttimedelay (($scriptstopmin-$scriptstartmin) * 60);
};
:set scripttimedelay (($scripttimedelay+$scriptstopsec)-$scriptstartsec);
################################################## ####
################################################## ####
:log info ("------------------------------------------");
:log warning ("Shaper:");
:log info ("MaxRate Download : " . $MaxRateDownload . " bps /" . $kbsmaxdown . " kbs / Upload : " . $MaxRateUpload . " bps /" . $kbsmaxup . " kbs");
:log info ("Active Users : Download : " . $activedowncount . " / Upload : " . $activeupcount );
:log info ("User Speed Download : " . $maxlimitdown . " bps /" . $kbsmaxlimitdown . " kbs / Upload : " . $maxlimitdown . " bps /" . $kbsmaxlimitup . " kbs" );
:log warning ("Performance Time: " . $scripttimedelay . " seconds.");
:log info ("------------------------------------------");
################################################## ####
################################################## ####
# (C) Inlarion icq 429-587 http://mikrotik.axiom-pro.ru/ Copyright!
################################################## ####
вот сам скрипт! нужно поправить синтас под версию 3.22!! он вобще под 4 - 5!!!
#Settings
################################################## ####
:local MaxRateDownload ("15000000");
:local MaxRateUpload ("15000000");
:local MaxRateDownloadNight ("20000000");
:local MaxRateUploadNight ("20000000");
:local ActiveThresholddown ("15000");
:local ActiveThresholdup ("15000");
:local usenighttime ("yes");
:local nighttimestart ("02:00");
:local nighttimestop ("08:00");
################################################## ####
#Internal Var
################################################## ####
:local z;
:local i;
:local ii;
:local userX;
:local timedelay (0);
:local startmin;
:local startsec;
:local stopmin;
:local stopsec;
:local scripttimedelay (0);
:local scriptstartmin;
:local scriptstartsec;
:local scriptstopmin;
:local scriptstopsec;
:local userscount ("0");
:local userstmp ("");
:local firstdowntmp ("");
:local firstuptmp ("");
:local twodowntmp ("");
:local twouptmp ("");
:local activedownuserstmp ("");
:local activeupuserstmp ("");
:local activedowncount ("0");
:local activeupcount ("0");
################################################## ####
################################################## ####
:set scriptstartmin ([: pick [/system clock get time] 3 5]);
:set scriptstartsec ([: pick [/system clock get time] 6 8]);
:if ($usenighttime = "yes") do={
:set nighttimestart ([: pick $nighttimestart 0 2] . [: pick $nighttimestart 3 5]);
:set nighttimestop ([: pick $nighttimestop 0 2] . [: pick $nighttimestop 3 5]);
:local currenthours ([: pick [/system clock get time] 0 2]);
:local currenttime ([: pick [/system clock get time] 0 2] . [: pick [/system clock get time] 3 5] );
:local acttime ("day");
:local starttime ("day");
:if ($currenthours < 10) do={ :set acttime ("night"); };
:if ( [: pick $nighttimestart 0 2] < 10) do={ :set starttime ("night"); };
:local night ("no");
:if ($starttime = "night") do={
:if ( $currenttime > $nighttimestart && $currenttime < $nighttimestop) do={ :set night ("yes"); };
};
:if ($starttime = "day") do={
:if ( $acttime = "day") do={
:if ( $currenttime >= $nighttimestart) do={ :set night ("yes"); };
};
:if ( $acttime = "night") do={
:if ( $currenttime < $nighttimestop ) do={ :set night ("yes"); };
};};
:if ($night = "yes") do={
:set MaxRateDownload ($MaxRateDownloadNight);
:set MaxRateUpload ($MaxRateUploadNight);
};
};
:set ActiveThresholddown ($ActiveThresholddown / 8);
:set ActiveThresholdup ($ActiveThresholdup / 8);
:foreach i in=[/ip firewall address-list find list="users"] do={ :set userX [/ip firewall address-list get $i address];
:set userscount ($userscount+1);
:set userstmp ($userstmp . $userX . ",");
};
:local users [:toarray $userstmp];
:set startmin ([: pick [/system clock get time] 3 5]);
:set startsec ([: pick [/system clock get time] 6 8]);
:global dcount ("1");
:for dcount from=1 to=$userscount step=1 do={
:set firstdowntmp ($firstdowntmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_down"] bytes] . ",");
:set firstuptmp ($firstuptmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_up"] bytes] . ",");
};
:set stopmin ([: pick [/system clock get time] 3 5]);
:set stopsec ([: pick [/system clock get time] 6 8]);
:global dcount ("1");
:for dcount from=1 to=$userscount step=1 do={
:set twodowntmp ($twodowntmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_down"] bytes] . ",");
:set twouptmp ($twouptmp . [/ip firewall mangle get [/ip firewall mangle find comment=[:pick $users ($dcount-1)] . "_up"] bytes] . ",");
};
:if ( $stopmin > $startmin) do={
:set timedelay (($stopmin-$startmin) * 60);
};
:set timedelay (($timedelay+$stopsec)-$startsec);
:local firstdown [:toarray $firstdowntmp];
:local firstup [:toarray $firstuptmp];
:local twodown [:toarray $twodowntmp];
:local twoup [:toarray $twouptmp];
:global dcount ("1");
:for dcount from=1 to=$userscount step=1 do={
:if ( ($ActiveThresholddown * $timedelay) < ([:pick $twodown ($dcount-1)] - [:pick $firstdown ($dcount-1)]) ) do={
:set activedownuserstmp ($activedownuserstmp . [:pick $users ($dcount-1)] . ",");
:set activedowncount ($activedowncount+1);
};
:if ( ($ActiveThresholdup * $timedelay) < ([:pick $twoup ($dcount-1)] - [:pick $firstup ($dcount-1)]) ) do={
:set activeupuserstmp ($activeupuserstmp . [:pick $users ($dcount-1)] . ",");
:set activeupcount ($activeupcount+1);
};
};
:local activedownusers [:toarray $activedownuserstmp];
:local activeupusers [:toarray $activeupuserstmp];
:local maxlimitdown ("0");
:local maxlimitup ("0");
:if ( $activedowncount > 0 ) do={
:set maxlimitdown ($MaxRateDownload/$activedowncount);
:global dcount ("1");
:for dcount from=1 to=$activedowncount step=1 do={
:if ([/queue tree get [find name=[:pick $activedownusers ($dcount-1)] . "_down"] max-limit] != $maxlimitdown) do={
/queue tree set [/queue tree find name=[:pick $activedownusers ($dcount-1)] . "_down"] max-limit=$maxlimitdown; };
};
};
:if ( $activeupcount > 0 ) do={
:set maxlimitup ($MaxRateUpload/$activeupcount);
:global dcount ("1");
:for dcount from=1 to=$activeupcount step=1 do={
:if ([/queue tree get [find name=[:pick $activeupusers ($dcount-1)] . "_up"] max-limit] != $maxlimitup) do={
/queue tree set [/queue tree find name=[:pick $activeupusers ($dcount-1)] . "_up"] max-limit=$maxlimitup; };
};
};
:local kbsmaxdown ($MaxRateDownload/1000);
:local kbsmaxup ($MaxRateUpload /1000);
:if ( $maxlimitdown = 0 ) do={ :set maxlimitdown ($MaxRateDownload); };
:if ( $maxlimitup = 0 ) do={ :set maxlimitup ($MaxRateUpload); };
:local kbsmaxlimitdown ($maxlimitdown/1024);
:local kbsmaxlimitup ($maxlimitup/1024);
:set scriptstopmin ([: pick [/system clock get time] 3 5]);
:set scriptstopsec ([: pick [/system clock get time] 6 8]);
:if ( $scriptstopmin > $scriptstartmin) do={
:set scripttimedelay (($scriptstopmin-$scriptstartmin) * 60);
};
:set scripttimedelay (($scripttimedelay+$scriptstopsec)-$scriptstartsec);
################################################## ####
################################################## ####
:log info ("------------------------------------------");
:log warning ("Shaper:");
:log info ("MaxRate Download : " . $MaxRateDownload . " bps /" . $kbsmaxdown . " kbs / Upload : " . $MaxRateUpload . " bps /" . $kbsmaxup . " kbs");
:log info ("Active Users : Download : " . $activedowncount . " / Upload : " . $activeupcount );
:log info ("User Speed Download : " . $maxlimitdown . " bps /" . $kbsmaxlimitdown . " kbs / Upload : " . $maxlimitdown . " bps /" . $kbsmaxlimitup . " kbs" );
:log warning ("Performance Time: " . $scripttimedelay . " seconds.");
:log info ("------------------------------------------");
################################################## ####
################################################## ####
# (C) Inlarion icq 429-587 http://mikrotik.axiom-pro.ru/ Copyright!
################################################## ####
Комментарий