动态ADSL 更新网关的问题!
wan网接口是1条动态ADSL每次拨号后网关有变化!! 从网上找到的自动更新网关。。 不灵!!请教大家。。 有什么好的办法!!
网上下的脚本文件
/interface pppoe-client
:foreach pppoeClient in do={
:local pppoeClientName
:local pppoeInterface
:local interfaceComment comment]
monitor $pppoeClientName once do={
:local findIndex [:find $interfaceComment "-"]
:local oldStatus ""
:local oldIP ""
:local ipAddress ""
:local newIP ""
:if (findIndex!=nothing) do={
:set oldStatus [:pick $interfaceComment 0 $findIndex]
:set oldIP [:pick $interfaceComment ($findIndex+1) [:len $interfaceComment]]
} else={
:set oldStatus $interfaceComment
}
:if ($status="connected") do={
:set ipAddress address]
:set newIP [:pick $ipAddress 0 [:find $ipAddress "/"]]
}
:if ($status!=$oldStatus||($status="connected"&&$oldStatus="connected"&&$oldIP!=$newIP)) do={
:if ($oldStatus="connected") do={
/ip address remove ($pppoeClientName . "_IP_Address")
/ip route remove ($pppoeClientName . "_Route")
}
:if ($status="connected") do={
/ip address add comment=($pppoeClientName . "_IP_Address") address=$ipAddress network=$newIP broadcast=$newIP interface=$pppoeClientName disabled=no
/ip route add comment=($pppoeClientName . "_Route") gateway=$newIP routing-mark=($pppoeClientName . "_Routing_Mark")
/interface set comment=($status . "-" . $newIP)
}
:if ($status="disconnected"||$status="dialing...") do={
/interface set comment=$status
}
}
}
}
/interface pppoe-client
:foreach pppoeClient in do={
:local pppoeClientName
:local pppoeInterface
:local interfaceComment comment]
:if ($interfaceComment!="")
{
:if ([:find $interfaceComment "connected"]!=nothing) do={
/ip address remove ($pppoeClientName . "_IP_Address")
/ip route remove ($pppoeClientName . "_Route")
}
/interface set comment=""
}
} :$ 你要动态更新干什么用呢? 映射 更新网关吧???你搞那么复杂做什么???
:global adsl "pppoe-out1"
:global new-ip [ /ip address get network ]
:global old-ip [ /ip route get gateway ]
:if ($new-ip != $old-ip) do={
:log info gateway=$new-ip]
:log info "adsl gateway ok"
}
就搞定了。 一条用得着网关更新吗??? 用interface来映射,而不用IP就行了
页:
[1]