#配置开始
#当检测到用户访问网页后,把用户加入两个地址池,一个保存3s,一个保存1d。如果发现已经加入1d地址列表,则不再加入3s地址列表。
/ip firewall mangle
add action=add-src-to-address-list address-list=src1 address-list-timeout=3s chain=prerouting comment="" disabled=no dst-port=80 protocol=tcp \
src-address=192.168.1.1-192.168.1.253 src-address-list=!src2
add action=add-src-to-address-list address-list=src2 address-list-timeout=1d chain=prerouting comment="" disabled=no port=80 protocol=tcp \
src-address=192.168.1.1-192.168.1.253
#开启透明代理,并让进入透明代理的用户都跳转到http://8.8.8.8。
/ip proxy
set always-from-cache=no cache-administrator=webmaster cache-hit-dscp=4 cache-on-disk=no enabled=yes max-cache-size=unlimited \
max-client-connections=600 max-fresh-time=3d max-server-connections=600 parent-proxy=0.0.0.0 parent-proxy-port=0 port=8080 \
serialize-connections=no src-address=0.0.0.0
#如果用户被加入3s地址列表,则此用户数据进入透明代理端口。
/ip firewall nat
add action=redirect chain=dstnat comment="" disabled=no dst-port=80 protocol=tcp src-address-list=src1 to-ports=8080
/ip proxy access
add action=deny comment="" disabled=no dst-host=!*ai800* redirect-to=http://8.8.8.8
#配置结束
#定义变量
#首页所在服务器IP
:local StrToAddress
:set StrToAddress 8.8.8.8
#首页所在服务器端口
:local StrToPort
:set StrToPort 80
#时限1,指定时限内跳到指定首页,设置1-5秒
:local StrTimeOut1
:set StrTimeOut1 2s
#时限2,指定时限内不跳到指定首页,3小时为3h,(测试是否有效可调为1分钟1m)
:local StrTimeOut2
:set StrTimeOut2 3h
ip firewall mangle add chain=prerouting protocol=tcp dst-port=80 src-address-list=!src2 \
action=add-src-to-address-list address-list=src1 address-list-timeout=$StrTimeOut1 comment=TimeOut1
ip firewall mangle add chain=prerouting protocol=tcp dst-port=80 \
action=add-src-to-address-list address-list=src2 address-list-timeout=$StrTimeOut2 comment=TimeOut2
ip firewall nat add chain=dstnat protocol=tcp dst-port=80 src-address-list=src1 \
action=dst-nat to-addresses=$StrToAddress to-ports=$StrToPort comment=ToAddress
|