让网维变得简单,快速,准确。拒绝浪费时间,解放出更多的时间陪陪家人。 注册 | 登陆

CTS穿透自动协议切换脚本(已添加脚本)

近期由于CTS2,CTS5(青岛服)PPTP协议出现异常,本站非常重视该问题,并且希望今后能避免这种问题出现。为此编写了自动切换协议脚本。用户只需修改脚本里对应的几个参数,然后定时执行,即可在侦测到问题时自动更换连接穿透服务器的协议。建议用户将该脚本加入到定时运行,若之前已存在CTS的连接,则会自动更名。建议5-10分钟循环执行一次。(取消了切换到PPTP)

ROS脚本代码
  1. ###使用前请确保你当前没有使用穿透进行管理###  
  2. ###请删除之前自己创建的CTS穿透VPN连接,方可使用本脚本。###  
  3. ###建议5-10分钟循环执行一次。6.38.5测试通过。###  
  4. ###定义CTS服务器IP###  
  5. :global ctsip 120.24.176.137  
  6. ###定义CTS服务器虚拟网关###  
  7. :global ctsgw 172.34.56.1  
  8. ###定义CTS服务器用户名###  
  9. :global ctsuser "user"  
  10. ###定义CTS服务器密码###  
  11. :global ctspass "passwd"  
  12. ###获取当前使用的CTS的VPN类型###  
  13. :global usedvpn ""  
  14. ###获取当前CTS连接状态###  
  15. :global stvpn   
  16. :if ([/interface pptp-client find name=CTS-PPTP]!=""do={  
  17. :set usedvpn pptp  
  18. :set stvpn [/interface pptp-client find name=CTS-PPTP running=yes]}  
  19. :if ([/interface l2tp-client find name=CTS-L2TP]!=""do={  
  20. :set usedvpn l2tp  
  21. :set stvpn [/interface l2tp-client find name=CTS-L2TP running=yes]}  
  22. :if ([/interface sstp-client find name=CTS-SSTP]!=""do={  
  23. :set usedvpn sstp  
  24. :set stvpn [/interface sstp-client find name=CTS-SSTP running=yes]}  
  25. :if ([/interface ovpn-client find name=CTS-OVPN]!=""do={  
  26. :set usedvpn ovpn  
  27. :set stvpn [/interface ovpn-client find name=CTS-OVPN running=yes]}  
  28. ###没有发现任何符合条件的穿透接口,我来创建一个###  
  29. :if (usedvpn=""do={  
  30. :if ([/interface pptp-client find connect-to=$ctsip]!=""do={  
  31. /interface pptp-client set [find connect-to=$ctsip] name=CTS-PPTP  
  32. :set usedvpn pptp}  
  33. :if ([/interface l2tp-client find connect-to=$ctsip]!=""do={  
  34. /interface l2tp-client set [find connect-to=$ctsip] name=CTS-L2TP  
  35. :set usedvpn l2tp}  
  36. :if ([/interface sstp-client find connect-to=($ctsip.":22")]!=""do={  
  37. /interface sstp-client set [find connect-to=($ctsip.":22")] name=CTS-SSTP  
  38. :set usedvpn sstp}  
  39. :if ([/interface ovpn-client find connect-to=$ctsip]!=""do={  
  40. /interface ovpn-client set [find connect-to=$ctsip] name=CTS-OVPN  
  41. :set usedvpn ovpn}}  
  42. :if (usedvpn=""do={/interface ovpn-client add cipher=aes128 connect-to=$ctsip port=110 name=CTS-OVPN user=$ctsuser password=$ctspass profile=default-encryption}  
  43. ###检测CTS当前连接是否正常,不正常则切换VPN协议###  
  44. :if ($stvpn=""do={  
  45. :if ($usedvpn="pptp"do={  
  46. /interface pptp-client remove [find name=CTS-PPTP]  
  47. /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  
  48. :if ($usedvpn="l2tp"do={  
  49. /interface l2tp-client remove [find name=CTS-L2TP]  
  50. /interface sstp-client  
  51. add connect-to=($ctsip.":22") disabled=no name=CTS-SSTP profile=default-encryption user=$ctsuser password=$ctspass}  
  52. :if ($usedvpn="sstp"do={  
  53. /interface sstp-client remove [find name=CTS-SSTP]  
  54. /interface ovpn-client add cipher=aes128 connect-to=$ctsip port=110 name=CTS-OVPN user=$ctsuser password=$ctspass profile=default-encryption}  
  55. :if ($usedvpn="ovpn"do={  
  56. /interface ovpn-client remove [find name=CTS-OVPN]  
  57. #/interface pptp-client add connect-to=$ctsip name=CTS-PPTP user=$ctsuser password=$ctspass profile=default-encryption disabled=no  
  58. /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  
  59. else={  
  60. :if ([/ping $ctsgw count=4]=0) do={  
  61. :if ($usedvpn="pptp"do={  
  62. /interface pptp-client remove [find name=CTS-PPTP]  
  63. /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  
  64. :if ($usedvpn="l2tp"do={  
  65. /interface l2tp-client remove [find name=CTS-L2TP]  
  66. /interface sstp-client  
  67. add connect-to=($ctsip.":22") disabled=no name=CTS-SSTP profile=default-encryption user=$ctsuser password=$ctspass}  
  68. :if ($usedvpn="sstp"do={  
  69. /interface sstp-client remove [find name=CTS-SSTP]  
  70. /interface ovpn-client add cipher=aes128 connect-to=$ctsip port=110 name=CTS-OVPN user=$ctsuser password=$ctspass profile=default-encryption}  
  71. :if ($usedvpn="ovpn"do={  
  72. /interface ovpn-client remove [find name=CTS-OVPN]  
  73. #/interface pptp-client add connect-to=$ctsip name=CTS-PPTP user=$ctsuser password=$ctspass profile=default-encryption disabled=no  
  74. /interface l2tp-client add connect-to=$ctsip disabled=no name=CTS-L2TP user=$ctsuser password=$ctspass profile=default-encryption}  
  75. }}  

 

Tags: ros, cts, vpn, 穿透, 切换

« 上一篇 | 下一篇 »

 

2条记录访客评论

引用 luiwendi 说过的话:
ROS5.24经测试无效

这个是6X脚本,另外不是特别差的第三手网络不需要使用这个脚本。

Post by 熊茂祥 on 2020, April 12, 10:21 AM 引用此文发表评论 #1

ROS5.24经测试无效

Post by luiwendi on 2020, March 5, 1:39 PM 引用此文发表评论 #2


发表评论

评论内容 (必填):