/// <summary> /// 添加网络路由 /// </summary> /// <param name="dicParams">取到的系统参数</param> /// <returns>返回添加结果</returns> private bool AddNetWorkRoute(List<MSysDicItemInfo> dicParams) { bool result = false; TestLink link = new TestLink(); try { ////先获取默认网关 string defaultGateWay = link.GetDefaultGateWay(); foreach (var dicParam in dicParams) { if (!string.IsNullOrEmpty(defaultGateWay)) { List<string> temp = dicParam.ParaValue.Split('|').ToList(); //////取到网关,添加路由 string addRouteResult = link.AddNetWorkRoute(temp[0], temp[1], defaultGateWay); if (addRouteResult.Contains("操作完成") || addRouteResult.Contains("对象已存在")) { result = true; } } else { result = false; } } } catch (Exception ex) { MessagePipe.ExcuteWriteMessageEvent("添加路由出现异常" + ex.Message.ToString(), Color.Red, true); result = false; } return result; }
/// <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); }
/// <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; }