mirror of
https://github.com/wifinigel/MikrotikScripting.git
synced 2025-06-21 01:15:43 +02:00
publish copy updates
This commit is contained in:
parent
4548f7c5c1
commit
8a3419b536
22 changed files with 63 additions and 48 deletions
|
@ -4,6 +4,6 @@
|
|||
|
||||
:for Number from=1 to=10 do={
|
||||
:local Result ($Number * $MULTIPLIER)
|
||||
:put ("This is an unusually long line. Here is the result $Number times \
|
||||
$MULTIPLIER is: $Result")
|
||||
:put ("This is an unusually long line. Here is the result $Number \
|
||||
times $MULTIPLIER is: $Result")
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
|
||||
:for Number from=1 to=10 do={
|
||||
:local Result ($Number * $MULTIPLIER);
|
||||
:put ("This is an unusually long line. Here is the result $Number times \
|
||||
$MULTIPLIER is: $Result");
|
||||
}
|
||||
:put ("This is an unusually long line. Here is the result $Number \
|
||||
times $MULTIPLIER is: $Result");
|
||||
}
|
|
@ -5,6 +5,6 @@
|
|||
:local GlobalScopeVar "I'm in the global scope!";
|
||||
|
||||
# Let's print it out
|
||||
:put ("Global variable contents = $GlobalScopeVar");
|
||||
:put ("Global scope variable contents = $GlobalScopeVar");
|
||||
|
||||
# ---- global scope end ----
|
|
@ -22,10 +22,10 @@ if ( [:typeof $WanInterfaces] != "array") do={
|
|||
# Let's step through the interfaces in the array
|
||||
# and print out their operation status
|
||||
:foreach WanInterface in=$WanInterfaces do={
|
||||
:local InterfaceIndex [/interface ethernet find name=$WanInterface];
|
||||
:local InterfaceId [/interface ethernet find name=$WanInterface];
|
||||
|
||||
:local UpDown "down";
|
||||
if ([:interface ethernet get $InterfaceIndex]->"running") do={
|
||||
if ([:interface ethernet get $InterfaceId]->"running") do={
|
||||
:set UpDown "up"
|
||||
}
|
||||
|
||||
|
|
|
@ -11,24 +11,27 @@
|
|||
# define a target web site
|
||||
:local WebSite "www.google.com";
|
||||
|
||||
# run a while loop until one minute interval expired
|
||||
# run a while loop until one minute interval has expired
|
||||
:while ( [/system clock get time] < $EndTime ) do={
|
||||
|
||||
:put "Getting web page from $WebSite";
|
||||
|
||||
# fetch a page from web site
|
||||
:local FetchResult [/tool fetch url=("https://$WebSite") mode=https \
|
||||
http-method=get as-value keep-result=no];
|
||||
:local FetchResult;
|
||||
:local TimeTaken [:time {
|
||||
:set FetchResult [/tool fetch url=("https://$WebSite") \
|
||||
mode=https http-method=get as-value keep-result=no];
|
||||
}];
|
||||
|
||||
if ($FetchResult->"status" = "finished") do={
|
||||
# print out how long page retrieval took (if successful)
|
||||
:local FetchDuration ($FetchResult->"duration");
|
||||
:put "Web page fetch time: $FetchDuration secs";
|
||||
:put "Web page fetch time: $TimeTaken secs";
|
||||
} else={
|
||||
# print failure message if fetch failed
|
||||
:put "Web page fetch failed";
|
||||
}
|
||||
|
||||
# pause for 5 seconds
|
||||
:delay 5;
|
||||
|
||||
}
|
||||
:put "One minute period has ended!"
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
# --- start of function ---
|
||||
:global MacColonRemoveFunc do={
|
||||
:local TidyMac "";
|
||||
for i from=0 to=([:len $1]-1) do={
|
||||
:local TmpValue [:pick $1 $i];
|
||||
for CharNumber from=0 to=([:len $1]-1) do={
|
||||
:local TmpValue [:pick $1 $CharNumber];
|
||||
:if ($TmpValue !=":") do={ :set TidyMac "$TidyMac$TmpValue" }
|
||||
}
|
||||
:return $TidyMac;
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
}
|
||||
|
||||
# data type checks passed, print the interface data
|
||||
:put "$InterfaceName: IP address = $InterfaceIp, speed = $InterfaceSpeed";
|
||||
:put "$InterfaceName: IP address = $InterfaceIp, speed = \
|
||||
$InterfaceSpeed";
|
||||
|
||||
}
|
||||
# --- end of function ---
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
# --- start of function ---
|
||||
:global PrintInterfaceAttrsFunc do={
|
||||
|
||||
# verify arg is correct type
|
||||
if ([:typeof $1] != "array") do={
|
||||
:error "Function argument is not an array!";
|
||||
}
|
||||
|
||||
# extract values from array passed as arg
|
||||
:local Args $1;
|
||||
:local InterfaceName ($Args->"ifname");
|
||||
:local InterfaceSpeed ($Args->"ifspeed");
|
||||
|
@ -34,12 +36,13 @@
|
|||
# --- end of function ---
|
||||
|
||||
# Let's call the function with some sample values in an array
|
||||
:local Args { ifname="WAN1"; ifspeed="100Mbps";
|
||||
:local Args { ifname="WAN1"; ifspeed="100Mbps"; \
|
||||
ifip="192.168.99.1/24" };
|
||||
$PrintInterfaceAttrsFunc $Args;
|
||||
|
||||
# Let's call the function with some other values in an array
|
||||
:set Args { ifname="ether2-LAN"; ifspeed="1000Mbps"; ifip="172.16.1.254/24" };
|
||||
:set Args { ifname="ether2-LAN"; ifspeed="1000Mbps"; \
|
||||
ifip="172.16.1.254/24" };
|
||||
$PrintInterfaceAttrsFunc $Args;
|
||||
|
||||
# Cleanup global namespace
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#
|
||||
:global RemoveSpaceFunc do={
|
||||
:local NewName ""
|
||||
for i from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $i]
|
||||
for CharNumber from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $CharNumber]
|
||||
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
|
||||
}
|
||||
:return $NewName
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#
|
||||
:global RemoveSpaceFunc do={
|
||||
:local NewName ""
|
||||
for i from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $i]
|
||||
for CharNumber from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $CharNumber]
|
||||
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
|
||||
}
|
||||
:return $NewName
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# filename: ch9-07-use-str-module.rsc
|
||||
|
||||
# import the functions we need and declare the function
|
||||
# import the functions we need and declare the functions
|
||||
# names we wish to use
|
||||
/import "ch9-06-str-funcs-mod.rsc"
|
||||
:global RemoveSpaceFunc;
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
|
||||
:for Number from=1 to=10 do={
|
||||
:local Result ($Number * $MULTIPLIER)
|
||||
:put ("This is an unusually long line. Here is the result $Number times \
|
||||
$MULTIPLIER is: $Result")
|
||||
:put ("This is an unusually long line. Here is the result \
|
||||
$Number times $MULTIPLIER is: $Result")
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
|
||||
:for Number from=1 to=10 do={
|
||||
:local Result ($Number * $MULTIPLIER);
|
||||
:put ("This is an unusually long line. Here is the result $Number times \
|
||||
$MULTIPLIER is: $Result");
|
||||
:put ("This is an unusually long line. Here is the result $Number \
|
||||
times $MULTIPLIER is: $Result");
|
||||
}
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
:local GlobalScopeVar "I'm in the global scope!";
|
||||
|
||||
# Let's print it out
|
||||
:put ("Global variable contents = $GlobalScopeVar");
|
||||
:put ("Global scope variable contents = $GlobalScopeVar");
|
||||
|
||||
# ---- global scope end ----
|
|
@ -22,10 +22,10 @@ if ( [:typeof $WanInterfaces] != "array") do={
|
|||
# Let's step through the interfaces in the array
|
||||
# and print out their operation status
|
||||
:foreach WanInterface in=$WanInterfaces do={
|
||||
:local InterfaceIndex [/interface/ethernet find name=$WanInterface];
|
||||
:local InterfaceId [/interface/ethernet find name=$WanInterface];
|
||||
|
||||
:local UpDown "down";
|
||||
if ([:interface/ethernet get $InterfaceIndex]->"running") do={
|
||||
if ([:interface/ethernet get $InterfaceId]->"running") do={
|
||||
:set UpDown "up"
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# script to report page load time of google.com
|
||||
|
||||
# get the current time
|
||||
:local CurrentTime [/system/clock get time];
|
||||
:local CurrentTime [/system clock get time];
|
||||
|
||||
# calculate the time in 1 minute
|
||||
:local EndTime ($CurrentTime + 00:01:00);
|
||||
|
@ -11,24 +11,28 @@
|
|||
# define a target web site
|
||||
:local WebSite "www.google.com";
|
||||
|
||||
# run a while loop until one minute interval expired
|
||||
# run a while loop until one minute interval has expired
|
||||
:while ( [/system/clock get time] < $EndTime ) do={
|
||||
|
||||
:put "Getting web page from $WebSite";
|
||||
|
||||
# fetch a page from web site
|
||||
:local FetchResult [/tool fetch url=("https://$WebSite") mode=https \
|
||||
http-method=get as-value keep-result=no];
|
||||
:local FetchResult;
|
||||
:local TimeTaken [:time {
|
||||
:set FetchResult [/tool fetch url=("https://$WebSite") \
|
||||
mode=https http-method=get as-value keep-result=no];
|
||||
}];
|
||||
|
||||
if ($FetchResult->"status" = "finished") do={
|
||||
# print out how long page retrieval took (if successful)
|
||||
:local FetchDuration ($FetchResult->"duration");
|
||||
:put "Web page fetch time: $FetchDuration secs";
|
||||
:put "Web page fetch time: $TimeTaken secs";
|
||||
} else={
|
||||
# print failure message if fetch failed
|
||||
:put "Web page fetch failed";
|
||||
}
|
||||
|
||||
# pause for 5 seconds
|
||||
:delay 5;
|
||||
|
||||
}
|
||||
:put "One minute period has ended!"
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
# --- start of function ---
|
||||
:global MacColonRemoveFunc do={
|
||||
:local TidyMac "";
|
||||
for i from=0 to=([:len $1]-1) do={
|
||||
:local TmpValue [:pick $1 $i];
|
||||
for CharNumber from=0 to=([:len $1]-1) do={
|
||||
:local TmpValue [:pick $1 $CharNumber];
|
||||
:if ($TmpValue !=":") do={ :set TidyMac "$TidyMac$TmpValue" }
|
||||
}
|
||||
:return $TidyMac;
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
}
|
||||
|
||||
# data type checks passed, print the interface data
|
||||
:put "$InterfaceName: IP address = $InterfaceIp, speed = $InterfaceSpeed";
|
||||
:put "$InterfaceName: IP address = $InterfaceIp, speed = \
|
||||
$InterfaceSpeed";
|
||||
|
||||
}
|
||||
# --- end of function ---
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
# --- start of function ---
|
||||
:global PrintInterfaceAttrsFunc do={
|
||||
|
||||
# verify arg is correct type
|
||||
if ([:typeof $1] != "array") do={
|
||||
:error "Function argument is not an array!";
|
||||
}
|
||||
|
||||
# extract values from array passed as arg
|
||||
:local Args $1;
|
||||
:local InterfaceName ($Args->"ifname");
|
||||
:local InterfaceSpeed ($Args->"ifspeed");
|
||||
|
@ -34,11 +36,12 @@
|
|||
# --- end of function ---
|
||||
|
||||
# Let's call the function with some sample values in an array
|
||||
:local Args { ifname="WAN1"; ifspeed="100Mbps"; ifip="192.168.99.1/24" };
|
||||
:local Args { ifname="WAN1"; ifspeed="100Mbps"; \
|
||||
ifip="192.168.99.1/24" };
|
||||
$PrintInterfaceAttrsFunc $Args;
|
||||
|
||||
# Let's call the function with some other values in an array
|
||||
:set Args { ifname="ether2-LAN"; ifspeed="1000Mbps";
|
||||
:set Args { ifname="ether2-LAN"; ifspeed="1000Mbps"; \
|
||||
ifip="172.16.1.254/24" };
|
||||
$PrintInterfaceAttrsFunc $Args;
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#
|
||||
:global RemoveSpaceFunc do={
|
||||
:local NewName ""
|
||||
for i from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $i]
|
||||
for CharNumber from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $CharNumber]
|
||||
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
|
||||
}
|
||||
:return $NewName
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#
|
||||
:global RemoveSpaceFunc do={
|
||||
:local NewName ""
|
||||
for i from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $i]
|
||||
for CharNumber from=0 to=([:len $1]-1) do={
|
||||
:local Tmp [:pick $1 $CharNumber]
|
||||
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
|
||||
}
|
||||
:return $NewName
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# filename: ch9-07-use-str-module.rsc
|
||||
|
||||
# import the functions we need and declare the function
|
||||
# import the functions we need and declare the functions
|
||||
# names we wish to use
|
||||
/import "ch9-06-str-funcs-mod.rsc"
|
||||
:global RemoveSpaceFunc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue