/// <summary>
        /// 是否连接上VPN服务器
        /// </summary>
        /// <param name="vpnAccount">VPN服务器供应账号信息</param>
        /// <param name="vpnServer">VPN服务器信息</param>
        /// <returns>返回连接结果</returns>
        public bool IslinkVpnServer(MVPNAccount vpnAccount, MVPNServer vpnServer)
        {
            bool linkResult = false;

            VpnHelper = new VPNHelper(vpnServer.Address, vpnServer.Area + vpnServer.Line, VpnAccount.Account, VpnAccount.Password);
            bool createOrUpdateResult = VpnHelper.CreateOrUpdateVPN();

            if (createOrUpdateResult)
            {
                ////连接VPN
                linkResult = VpnHelper.TryConnectVPN();
                if (linkResult)
                {
                    DateTime startTime    = DateTime.Now;
                    string   testLinkInfo = new TestLink().GetPingStr("www.baidu.com", 32, 200, 3);
                    if (testLinkInfo.Contains("100% 丢失"))
                    {
                        ////访问超时,也认为IP不可用
                        ////记录交互日志
                        string request = "VPN通道名称:" + vpnServer.Area + vpnServer.Line + ";VPN账号:" + vpnAccount.Account;
                        RecordLog.RecordInteractionLog(vpnAccount.Account, "连接VPN成功后,测试请求外网", request, testLinkInfo, DateTime.Now.Subtract(startTime), vpnServer.Address);
                        linkResult = false;
                    }

                    MessagePipe.ExcuteWriteMessageEvent(testLinkInfo, Color.Green, false);
                }
            }

            return(linkResult);
        }
Example #2
0
 /// <summary>
 /// Соединиться с БД
 /// </summary>
 /// <returns>true, если соединение успешно. иначе - ApplicationException</returns>
 public bool Connect()
 {
     try
     {
         VPNHelper.CheckControlNetwork();
         _connection.Open();
     }
     catch (Exception exc)
     {
         throw new ApplicationException("Невозможно подключиться к БД", exc);
     }
     return(true);
 }
Example #3
0
        /// <summary>
        /// 切换IP
        /// </summary>
        public static void ChangeIp()
        {
            VPNHelper vpn  = new VPNHelper();
            SinASDL   asdl = new SinASDL();

            while (true)
            {
                asdl.ASDLName = Config.BroadbandName;
                asdl.Username = Config.BroadbandUser;
                asdl.Password = Config.BroadbandPswd;
                vpn.VPNName   = asdl.ASDLName;
                vpn.TryDisConnectVPN(asdl.ASDLName);
                Thread.Sleep(5000);
                if (asdl.Connect() == 0)
                {
                    break;
                }
            }
        }