<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="CTS穿透自动协议切换脚本(已添加脚本)">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">熊茂祥</a><br />时间:2017-07-18 10:49<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">ROS</a><br />标签:<a href="index.php?action=tags&amp;item=ros&amp;hash=">ros</a>, <a href="index.php?action=tags&amp;item=cts&amp;hash=">cts</a>, <a href="index.php?action=tags&amp;item=vpn&amp;hash=">vpn</a>, <a href="index.php?action=tags&amp;item=%E7%A9%BF%E9%80%8F&amp;hash=">穿透</a>, <a href="index.php?action=tags&amp;item=%E5%88%87%E6%8D%A2&amp;hash=">切换</a><br />内容:
近期由于CTS2,CTS5(青岛服)的PPTP协议出现异常，本站非常重视该问题，并且希望今后能避免这种问题出现。为此编写了自动切换协议脚本。用户只需修改脚本里对应的几个参数，然后定时执行，即可在侦测到问题时自动更换连接穿透服务器的协议。建议用户将该脚本加入到定时运行，若之前已存在CTS的连接，则会自动更名。建议5-10分钟循环执行一次。（取消了切换到PPTP）


 


ROS脚本代码


    ###使用前请确保你当前没有使用穿透进行管理###  

    ###请删除之前自己创建的CTS穿透VPN连接，方可使用本脚本。###  

    ###建议5-10分钟循环执行一次。6.38.5测试通过。###  

    ###定义CTS服务器IP###  

    :global ctsip 120.24.176.137  

    ###定义CTS服务器虚拟网关###  

    :global ctsgw 172.34.56.1  

    ###定义CTS服务器用户名###  

    :global ctsuser &quot;user&quot;  

    ###定义CTS服务器密码###  

    :global ctspass &quot;passwd&quot;  

    ###获取当前使用的CTS的VPN类型###  

    :global usedvpn &quot;&quot;  

    ###获取当前CTS连接状态###  

    :global stvpn   

    :if ([/interface pptp-client find name=CTS-PPTP]!=&quot;&quot;) do={  

    :set usedvpn pptp  

    :set stvpn [/interface pptp-client find name=CTS-PPTP running=yes]}  

    :if ([/interface l2tp-client find name=CTS-L2TP]!=&quot;&quot;) do={  

    :set usedvpn l2tp  

    :set stvpn [/interface l2tp-client find name=CTS-L2TP running=yes]}  

    :if ([/interface sstp-client find name=CTS-SSTP]!=&quot;&quot;) do={  

    :set usedvpn sstp  

    :set stvpn [/interface sstp-client find name=CTS-SSTP running=yes]}  

    :if ([/interface ovpn-client find name=CTS-OVPN]!=&quot;&quot;) do={  

    :set usedvpn ovpn  

    :set stvpn [/interface ovpn-client find name=CTS-OVPN running=yes]}  

    ###没有发现任何符合条件的穿透接口,我来创建一个###  

    :if (usedvpn=&quot;&quot;) do={  

    :if ([/interface pptp-client find connect-to=$ctsip]!=&quot;&quot;) do={  

    /interface pptp-client set [find connect-to=$ctsip] name=CTS-PPTP  

    :set usedvpn pptp}  

    :if ([/interface l2tp-client find connect-to=$ctsip]!=&quot;&quot;) do={  

    /interface l2tp-client set [find connect-to=$ctsip] name=CTS-L2TP  

    :set usedvpn l2tp}  

    :if ([/interface sstp-client find connect-to=($ctsip.&quot;:22&quot;)]!=&quot;&quot;) do={  

    /interface sstp-client set [find connect-to=($ctsip.&quot;:22&quot;)] name=CTS-SSTP  

    :set usedvpn sstp}  

    :if ([/interface ovpn-client find connect-to=$ctsip]!=&quot;&quot;) do={  

    /interface ovpn-client set [find connect-to=$ctsip] name=CTS-OVPN  

    :set usedvpn ovpn}}  

    :if (usedvpn=&quot;&quot;) do={/interface ovpn-client add cipher=aes128 connect-to=$ctsip port=110 name=CTS-OVPN user=$ctsuser password=$ctspass profile=default-encryption}  

    ###检测CTS当前连接是否正常，不正常则切换VPN协议###  

    :if ($stvpn=&quot;&quot;) do={  

    :if ($usedvpn=&quot;pptp&quot;) do={  

    /interface pptp-client remove [find name=CTS-PPTP]  

    /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  

    :if ($usedvpn=&quot;l2tp&quot;) do={  

    /interface l2tp-client remove [find name=CTS-L2TP]  

    /interface sstp-client  

    add connect-to=($ctsip.&quot;:22&quot;) disabled=no name=CTS-SSTP profile=default-encryption user=$ctsuser password=$ctspass}  

    :if ($usedvpn=&quot;sstp&quot;) do={  

    /interface sstp-client remove [find name=CTS-SSTP]  

    /interface ovpn-client add cipher=aes128 connect-to=$ctsip port=110 name=CTS-OVPN user=$ctsuser password=$ctspass profile=default-encryption}  

    :if ($usedvpn=&quot;ovpn&quot;) do={  

    /interface ovpn-client remove [find name=CTS-OVPN]  

    #/interface pptp-client add connect-to=$ctsip name=CTS-PPTP user=$ctsuser password=$ctspass profile=default-encryption disabled=no  

    /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  

    } else={  

    :if ([/ping $ctsgw count=4]=0) do={  

    :if ($usedvpn=&quot;pptp&quot;) do={  

    /interface pptp-client remove [find name=CTS-PPTP]  

    /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  

    :if ($usedvpn=&quot;l2tp&quot;) do={  

    /interface l2tp-client remove [find name=CTS-L2TP]  

    /interface sstp-client  

    add connect-to=($ctsip.&quot;:22&quot;) disabled=no name=CTS-SSTP profile=default-encryption user=$ctsuser password=$ctspass}  

    :if ($usedvpn=&quot;sstp&quot;) do={  

    /interface sstp-client remove [find name=CTS-SSTP]  

    /interface ovpn-client add cipher=aes128 connect-to=$ctsip port=110 name=CTS-OVPN user=$ctsuser password=$ctspass profile=default-encryption}  

    :if ($usedvpn=&quot;ovpn&quot;) do={  

    /interface ovpn-client remove [find name=CTS-OVPN]  

    #/interface pptp-client add connect-to=$ctsip name=CTS-PPTP user=$ctsuser password=$ctspass profile=default-encryption disabled=no  

    /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  

    }}  





 
</p><p>
<a href="index.php?action=comments&amp;articleid=218&amp;hash=">查看评论</a><br />
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
