2013年8月12日 星期一

利用VBS完成自動撥接VPN網路

利用VBS完成自動撥接VPN網路


本篇要分享-利用VBS完成自動撥接VPN網路,有興趣的(C/P)同好,歡迎來(C/P)一下哈哈 ^ ^。









DIALNAME = "nabrovpn"              '連線名稱


DIALUSER = "NS25423"               '連線帳號 NS[IP]


DIALPASS = "nabro25423"            '連線密碼 nabro[IP]


 


' ******** dim check ,check_cht


'dim check = 1


'dim check_cht = 1


 


' *******create ping object


Set WshShell = CreateObject("WScript.Shell")


 


 


 


' *******do ping hinet , if ok connect vpn


do                


RetCode = WshShell.Run("ping 168.95.1.1", 0, true)


 If RetCode = 0 Then


  WScript.Sleep(20000)                                 


  WshShell.Run "rasdial " & DIALNAME & " " & DIALUSER & " " & DIALPASS, 0


 End If


loop while RetCode <> 0


 


' ******sleep for net step


WScript.Sleep(30000)


 


' ******do ping vpn host , if not connect vpn


do


RetCode = WshShell.Run("ping 254.17.254.254", 0, true)


 If RetCode <> 0 Then


   WshShell.Run "rasdial " & DIALNAME & " /DISCONNECT", 0, true


   WScript.Sleep(60000)


   WScript.Sleep(60000)


   WScript.Sleep(60000)


   WScript.Sleep(60000)


   ' *******check cht if ok , connect vpn


     do


      RetCode = WshShell.Run("ping 168.95.1.1", 0, true)


      If RetCode = 0 Then                               


       WshShell.Run "rasdial " & DIALNAME & " " & DIALUSER & " " & DIALPASS, 0


      End If


     loop while RetCode <> 0


 End If


   WScript.Sleep(60000)


loop while check=check



 


沒有留言:

張貼留言