Upload
abel-chaina-gonzales
View
91
Download
5
Embed Size (px)
DESCRIPTION
Código en script para configurar equipos mikrotik con RouterOS
Citation preview
E:\Downloads\Mis Scripts MT.txt martes, 03 de febrero de 2015 13:02
# Queue automatico
:for e from=3 to=254 do={
/queue simple add name="usuario $e" target-addresses="192.168.1.$e"
max-limit=256000/512000 queue=pcq-up/pcq-down total-queue=default
}
------------------------------------------------------------------
# Corte Automatico por Fecha: By TechN9ne Inc. v0.2
# E-mail: [email protected]
# Comentario: {nov/11/2013}
#
:global TiempoSistema [/system clock get time]
:global FechaSistema [/system clock get date]
:local Contador [/ip hotspot user print count-only]
:local Comentario
:local Detalle
:local Accion
:local FechaCorte
:local Usuario
for x from= 0 to=($Contador - 1) do={
:log info $x
:set Comentario [/ip hotspot user get $x comment]
:set Usuario [/ip hotspot user get $x name]
:log info $Usuario
:for i from=([:len $Comentario] - 1) to=0 do={
:if ([:pick $Comentario $i] = "}") do={
:set Detalle [:pick $Comentario ($i+1) ([:len $Comentario])]
:set FechaCorte [:pick $Comentario 1 $i]
}
}
:if ($FechaCorte = $FechaSistema) do={
/ip hotspot user set [find name=$Usuario] disabled=yes comment="{SYSTEM -
$FechaSistema}$Detalle"
}
:set Usuario
:set FechaCorte
}
:set Contador
------------------------------------------------------------------
# Corte Automatico por Fecha: By TechN9ne Inc. v0.1
# E-mail: [email protected]
# Comentario: {nov/11/2013}
#
:global TiempoSistema [/system clock get time]
:global FechaSistema [/system clock get date]
:local contador [/ip hotspot user print count-only]
:local usercomentario
:local detalle
:local accion
:local fecha
-1-
E:\Downloads\Mis Scripts MT.txt martes, 03 de febrero de 2015 13:02
:local usuario
for x from= 0 to=($contador - 1) do={
:log info $x
:set usercomentario [/ip hotspot user get $x comment]
:set usuario [/ip hotspot user get $x name]
:log info $usercomentario
:log info $usuario
:for i from=([:len $usercomentario] - 1) to=0 do={
:if ([:pick $usercomentario $i] = "}") do={
:log info [:pick $usercomentario 0 $i]
:log info [:pick $usercomentario $i (:len $usercomentario)]
:set detalle [:pick $usercomentario 0 $i]
}
}
:for j from=([:len $detalle] - 1) to=0 do={
:if ([:pick $detalle $j] = "{") do={
:log info [:pick $detalle 0 $j]
:log info [:pick $detalle ($j+1) [:len $detalle]]
:set accion [:pick $detalle 0 $j]
:set fecha [:pick $detalle ($j+1) [:len $detalle]]
}
}
:if ($fecha = $FechaSistema) do={
:log info "valor igual";
/ip hotspot user set [find name=$usuario] disabled=yes
} else={
:log info "valor desigual";
}
}
#----------------------------------------------------------
# Envio Automatico de Backup a server FTP: By TechN9ne Inc.
# E-mail: [email protected]
#
/tool fetch address=192.168.254.1 src-path=MT-Two-BKP.backup user=admin mode=ftp
password=731c0n3 dst-path=MKT-Two-BKP.backup upload=yes
/tool fetch address=allteck-juliaca.comeze.com src-path=autosupout.backup user=a3492542
mode=ftp password=02MkubnT01 dst-path=autosupout.backup upload=yes
:local ftpurl "mkrestore.site40.net"
:local ftpuser "a6101789"
:local ftppassword "000webhost"
:local ftpfilename "autosupout0C01.backup"
[ /system backup save name=$ftpfilename ]
[ /tool fetch address=$ftpurl src-path=autosupout.backup user=$ftpuser mode=ftp
password=$ftppassword dst-path=$ftpfilename upload=yes ]
[ /file remove $ftpfilename ]
#---------------------------------------------
# Mikrotik Hotspot Expire users after 7 days
#
/ip hotspot user profile
{
-2-
E:\Downloads\Mis Scripts MT.txt martes, 03 de febrero de 2015 13:02
:local date [ /system clock get date ]
:if ( [ /ip hotspot user get $user comment ] = "" ) do={
[ /ip hotspot user set $user comment=$date ]
}
}
/system scheduler add name=expire-hotspot-users on-event="/system script run
expire-hotspot-users" \
policy=read,write start-time=00:05:00 interval=1d
/system script add name=expire-hotspot-users
{
:local offset 7
:global today
{
:local date [ /system clock get date ]
:local montharray (
"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ([ :find $montharray $monthtxt] )
:for nodays from=0 to=$months do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}
:foreach i in [ /ip hotspot user find where disabled=no ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray (
"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ( [ :find $montharray $monthtxt ] )
:for nodays from=0 to=$months do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:log info "HOTSPOT EXPIRE SCRIPT: Disabling Hotspot user $name first logged in $date"
[ /ip hotspot user disable $i ]
[ /ip hotspot active remove [find where user=$user] ]
}
}
}
}
# Envio automatico Respaldo Configuracion a E-mail
#
-3-
E:\Downloads\Mis Scripts MT.txt martes, 03 de febrero de 2015 13:02
/export file=TC28-8291
/system backup save name=autosupout.backup
:delay 10s
/tool e-mail send tls=yes to="[email protected]" subject="$[/system identity get name]
BackupTC28-8291" body="Archivo de configuracion - $[/system clock get date]"
file=TC28-8291.rsc
/tool e-mail send tls=yes to="[email protected]" subject="$[/system identity get name]
Respaldo-8291" body="Archivo de respaldo - $[/system clock get date]" file=autosupout.backup
###
# Queue type
/queue type
add kind=pcq name=pcq-up pcq-classifier=src-address pcq-limit=50 pcq-rate=0
pcq-total-limit=2000
add kind=pcq name=pcq-down pcq-classifier=dst-address pcq-limit=50 pcq-rate=0
pcq-total-limit=2000
--------------------------------------------------------------------
# Bloque por layer-7 de Facebook, Youtube, Xhamster.
# jul/09/2013 09:32:47 by RouterOS 5.25
# software id = ETSQ-E7RS
#
/ip firewall layer7-protocol
add name=facebook regexp="^.*(facebook).*\$"
add name=youtube regexp="^.*(youtube).*\$"
add name=xhamster regexp="^.*(xhamster).*\$"
/ip firewall filter
add action=drop chain=forward comment="" disabled=no layer7-protocol=facebook
src-address=172.16.2.250
add action=drop chain=forward comment="" disabled=no layer7-protocol=youtube
src-address=172.16.2.250
add action=drop chain=forward comment="" disabled=no layer7-protocol=xhamster
src-address=172.16.2.250
---------------------------------------------------------------------
Company: Allteck SAC
License ID: f07168095a63b8e432be5d09d816600e
# Script Scheduler para Deshabilitar user Hotspot:
/system script
add name=Deshabilitarhugo policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
source="/ip hotspot user disable [find name=\"hugo\"]\r\
\n/ip hotspot cookie remove [find user=\"hugo\"]\r\
\n/ip hotspot active remove [find user=\"hugo\"]"
/system scheduler
add name=Deshabilitarhugo on-event="/system script run Deshabilitarhugo" \
policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
start-date=nov/30/2013 start-time=00:00:00
----------------------------------------------------------------------
# Obtener IP Publica desde una URL
#
/tool fetch url="http://api.hostip.info/get_html.php" mode=http
-4-
E:\Downloads\Mis Scripts MT.txt martes, 03 de febrero de 2015 13:02
-5-