Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 取的默认网关
        /// </summary>
        /// <returns>返回网关地址</returns>
        public string GetDefaultGateWay()
        {
            string defaultGateWay = string.Empty;

            try
            {
                string        gateWayStr = this.ExcuteOrder("route print | find \"0.0.0.0\"");
                List <string> temp       = gateWayStr.Split(new char[] { ' ' }).ToList();
                List <string> iplist     = new List <string>();
                foreach (var str in temp)
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        iplist.Add(str);
                        if (iplist.Count > 3)
                        {
                            break;
                        }
                    }
                }

                if (iplist != null && iplist.Count > 3)
                {
                    defaultGateWay = iplist[2];
                }
            }
            catch (Exception ex)
            {
                MessagePipe.ExcuteWriteMessageEvent("取默认网关异常" + ex.Message.ToString(), Color.Green, false);
            }

            return(defaultGateWay);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建或更新一个VPN连接(指定VPN名称,及IP)
        /// </summary>
        /// <param name="updateVPNname">更新vpn名称</param>
        /// <param name="updateVPNip">更新VPN地址</param>
        /// <returns>操作成功:true,操作失败:false</returns>
        public bool CreateOrUpdateVPN(string updateVPNname, string updateVPNip)
        {
            bool     result    = true;
            DateTime startTime = DateTime.Now;
            string   msg       = string.Empty;

            try
            {
                RasDialer    dialer            = new RasDialer();
                RasPhoneBook allUsersPhoneBook = new RasPhoneBook();
                allUsersPhoneBook.Open();

                // 如果已经该名称的VPN已经存在,则更新这个VPN服务器地址
                if (allUsersPhoneBook.Entries.Contains(updateVPNname))
                {
                    allUsersPhoneBook.Entries[updateVPNname].PhoneNumber = updateVPNip;
                    ////不管当前VPN是否连接,服务器地址的更新总能成功,如果正在连接,则需要VPN重启后才能起作用
                    bool updateResult = allUsersPhoneBook.Entries[updateVPNname].Update();
                    msg = "更新VPN服务器通道为:" + updateVPNip;
                    if (updateResult)
                    {
                        MessagePipe.ExcuteWriteMessageEvent(msg + "成功", Color.Green, false);
                    }
                    else
                    {
                        MessagePipe.ExcuteWriteMessageEvent(msg + "失败", Color.Green, false);
                    }
                }
                else
                {
                    ////创建一个新VPN
                    RasEntry entry = RasEntry.CreateVpnEntry(updateVPNname, updateVPNip, RasVpnStrategy.PptpFirst, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));

                    allUsersPhoneBook.Entries.Add(entry);
                    dialer.EntryName = updateVPNname;

                    dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
                    msg = "新建VPN通道:" + updateVPNip + "成功";
                    MessagePipe.ExcuteWriteMessageEvent(msg, Color.Green, false);
                }
            }
            catch (Exception ex)
            {
                result = false;
                MessagePipe.ExcuteWriteMessageEvent("更新或创建VPN通道异常:" + ex.Message.ToString(), Color.Green, true);
            }
            finally
            {
                ////记录交互日志
                string request = "VPN通道名称:" + updateVPNname + ";VPN账号:" + this.userName + ";VPN地址:" + updateVPNip;
                RecordLog.RecordInteractionLog(updateVPNname, "创建VPN通道", request, msg, DateTime.Now.Subtract(startTime), updateVPNip);
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 调用IP监控组件
        /// </summary>
        /// <returns>返回true,Ip被限。返回false,IP没有被限制</returns>
        private bool InvokeIpMonitor()
        {
            bool result = false;

            while (true && !SignalControl.Issuspend)
            {
                double sleepTime = 5;
                try
                {
                    ////取监控间隔时间
                    string intervatTime = SysParamHelper.GetParamById <string>("ITZC_YW_CheckIPLockedIntervalTime", "xxxxx");
                    if (intervatTime == "xxxxx")
                    {
                        intervatTime = "5";
                    }

                    sleepTime = Convert.ToDouble(intervatTime);
                    MessagePipe.ExcuteWriteMessageEvent("开始调用监控组件,调用过后睡" + sleepTime + "分钟", Color.Red, false);
                    //////调用监控组件
                    MatchIpLimitRule iplimit = new MatchIpLimitRule();
                    result = iplimit.IslimitIp();

                    ////如果发现需要替换IP,并且距离上一次替换的时间间隔大于2分钟
                    if (result)
                    {
                        if (DateTime.Now.Subtract(this.replaceIpTime).Minutes > 2)
                        {
                            MessagePipe.ExcuteWriteMessageEvent("检测到IP:" + VpnServer.Address + "被限", Color.Red, true);
                            this.replaceIpTime = DateTime.Now;
                            break;
                        }
                        else
                        {
                            MessagePipe.ExcuteWriteMessageEvent("检测到IP被限,但距离上次替换时间间隔不到2分钟,暂不替换", Color.Red, true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessagePipe.ExcuteWriteMessageEvent("调用监控组件异常" + ex.Message.ToString(), Color.Red, true);
                }
                finally
                {
                    Thread.Sleep(TimeSpan.FromMinutes(sleepTime));
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取一个关键词
        /// </summary>
        /// <returns>返回关键词</returns>
        private string GetOneKeyWord()
        {
            string result = string.Empty;

            if (keywordsList != null && keywordsList.Count > 0)
            {
                result = keywordsList[0];
                keywordsList.RemoveAt(0);
            }
            else
            {
                MessagePipe.ExcuteWriteMessageEvent("处理完成", 0);
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取当前正在连接中的VPN名称
        /// </summary>
        /// <returns>返回当前连接的VPN名称</returns>
        public List <string> GetCurrentConnectingVPNNames()
        {
            List <string> connectingVPNList = new List <string>();

            try
            {
                Process proIP = new Process();

                proIP.StartInfo.FileName               = "cmd.exe ";
                proIP.StartInfo.UseShellExecute        = false;
                proIP.StartInfo.RedirectStandardInput  = true;
                proIP.StartInfo.RedirectStandardOutput = true;
                proIP.StartInfo.RedirectStandardError  = true;
                ////不显示cmd窗口
                proIP.StartInfo.CreateNoWindow = true;
                proIP.Start();

                proIP.StandardInput.WriteLine(rasDialFileName);
                proIP.StandardInput.WriteLine("exit");

                // 命令行运行结果
                string strResult = proIP.StandardOutput.ReadToEnd();
                proIP.Close();

                Regex regger = new Regex("(?<=已连接\r\n)(.*\n)*(?=命令已完成)", RegexOptions.Multiline);

                // 如果匹配,则说有正在连接的VPN
                if (regger.IsMatch(strResult))
                {
                    string[] list = regger.Match(strResult).Value.ToString().Split('\n');
                    for (int index = 0; index < list.Length; index++)
                    {
                        if (list[index] != string.Empty)
                        {
                            connectingVPNList.Add(list[index].Replace("\r", string.Empty));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessagePipe.ExcuteWriteMessageEvent("获取正在连接的VPN异常:" + ex.Message.ToString(), Color.Red, true);
            }

            // 没有正在连接的VPN,则直接返回一个空List<string>
            return(connectingVPNList);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 保存日志按钮
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void ToolItemSaveLog_Click(object sender, EventArgs e)
        {
            ////利用SaveFileDialog,让用户指定文件的路径名
            SaveFileDialog saveDlg = new SaveFileDialog();

            saveDlg.Filter = "文本文件|*.txt";
            if (saveDlg.ShowDialog() == DialogResult.OK)
            {
                FileStream   fs = null;
                StreamWriter sw = null;
                try
                {
                    // 创建文件,将textBox1中的内容保存到文件中
                    // saveDlg.FileName 是用户指定的文件路径
                    fs = File.Open(saveDlg.FileName, FileMode.Create, FileAccess.Write);
                    sw = new StreamWriter(fs);
                    List <string> recordStr = WorkingLog.LogStr.ToString().Split(Environment.NewLine.ToCharArray()).ToList();
                    foreach (string line in recordStr)
                    {
                        sw.WriteLine(line);
                    }
                }
                catch (Exception ex)
                {
                    MessagePipe.ExcuteWriteMessageEvent("保存日志文件失败" + ex.Message.ToString(), Color.Red, false);
                }
                finally
                {
                    if (sw != null)
                    {
                        ////关闭文件
                        sw.Flush();
                        sw.Close();
                    }

                    if (fs != null)
                    {
                        fs.Close();
                    }
                }

                ////提示用户:文件保存的位置和文件名
                MessageBox.Show("文件已成功保存到" + saveDlg.FileName);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 尝试连接VPN(指定VPN名称,用户名,密码)
        /// </summary>
        /// <param name="connVpnName">vpn名称</param>
        /// <param name="connUserName">连接的用户名称</param>
        /// <param name="connPassWord">连接的密码</param>
        /// <returns>连接成功true,连接失败false</returns>
        public bool TryConnectVPN(string connVpnName, string connUserName, string connPassWord)
        {
            bool     result    = false;
            DateTime startTime = DateTime.Now;
            string   linkInfo  = string.Empty;

            try
            {
                string args = string.Format("{0} {1} {2}", connVpnName, connUserName, SecurityUtility.DecryptString(connPassWord));

                ProcessStartInfo myProcess = new ProcessStartInfo(this.vpnProcess, args);

                myProcess.CreateNoWindow = true;

                myProcess.UseShellExecute        = false;
                myProcess.RedirectStandardOutput = true;
                var excuteResult = Process.Start(myProcess);
                linkInfo = excuteResult.StandardOutput.ReadToEnd();
                linkInfo = linkInfo.Replace("\n", string.Empty);
                if (linkInfo.Contains("已连接"))
                {
                    result = true;
                }
                else
                {
                    MessagePipe.ExcuteWriteMessageEvent("登陆失败,账号:" + connUserName + "密码:" + SecurityUtility.EncryptDES(connPassWord) + "VPN服务器:" + this.vpnIP, Color.Green, true);
                }

                MessagePipe.ExcuteWriteMessageEvent(connVpnName + "登陆验证结果:" + linkInfo, Color.Green, false);
            }
            catch (Exception ex)
            {
                string msg = "登陆异常,账号:" + connUserName + "密码:" + SecurityUtility.EncryptDES(connPassWord) + "VPN服务器:" + this.vpnIP;
                LogManager.Log.WriteException(new AppException(msg, ex, ExceptionLevel.Info));
            }
            finally
            {
                ////记录交互日志
                string request = "VPN通道名称:" + connVpnName + ";VPN账号:" + connUserName;
                RecordLog.RecordInteractionLog(connUserName, "通过用账号和密码登陆", request, linkInfo, DateTime.Now.Subtract(startTime), this.vpnIP);
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 执行
        /// </summary>
        private void Excute()
        {
            ////调用一个方法取一条
            keyword = this.GetOneKeyWord();
            if (!string.IsNullOrEmpty(keyword))
            {
                MessagePipe.ExcuteWriteMessageEvent("开始处理关键词【" + keyword + "】", 0);

                string tempword = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("GB2312"));
                tempword = tempword.ToUpper();
                string url = string.Format("http://index.baidu.com/?tpl=crowd&word={0}", tempword);
                this.webBrowser1.Navigate(url);
                //this.webBrowser1.Document.GetElementById("schword").SetAttribute("value", keyword);
                //this.webBrowser1.Document.GetElementById("schsubmit").InvokeMember("click");

                Fiddler.FiddlerApplication.SetAppDisplayName("FiddlerCoreDemoApp");
                FiddlerApplication.Startup(7777, FiddlerCoreStartupFlags.Default);
                //FiddlerApplication.BeforeRequest += BeforeRequest;
                Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS)
                {
                    oS.bBufferResponse = true;
                    Monitor.Enter(oAllSessions);
                    oAllSessions.Add(oS);
                    Monitor.Exit(oAllSessions);
                    oS["X-AutoAuth"] = "(default)";
                    if ((oS.oRequest.pipeClient.LocalPort == iSecureEndpointPort) && (oS.hostname == sSecureEndpointHostname))
                    {
                        oS.utilCreateResponseAndBypassServer();
                        oS.oResponse.headers.SetStatus(200, "Ok");
                        oS.oResponse["Content-Type"]  = "text/html; charset=UTF-8";
                        oS.oResponse["Cache-Control"] = "private, max-age=0";
                        oS.utilSetResponseBody("<html><body>Request for httpS://" + sSecureEndpointHostname + ":" + iSecureEndpointPort.ToString() + " received. Your request was:<br /><plaintext>" + oS.oRequest.headers.ToString());
                    }
                };
                FiddlerApplication.BeforeResponse += FiddlerApplication_BeforeResponse;
                Fiddler.FiddlerApplication.AfterSessionComplete += delegate(Fiddler.Session oS)
                {
                    //Console.WriteLine("Finished session:\t" + oS.fullUrl);
                    //MessagePipe.ExcuteWriteMessageEvent ("Session list contains: " + oAllSessions.Count.ToString() + " sessions",0);
                };
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// 删除指定名称的VPN
 /// 如果VPN正在运行,一样会在电话本里删除,但是不会断开连接,所以,最好是先断开连接,再进行删除操作
 /// </summary>
 /// <param name="delVpnName">待删除的VPN名称</param>
 public void TryDeleteVPN(string delVpnName)
 {
     if (!string.IsNullOrEmpty(delVpnName))
     {
         RasDialer    dialer            = new RasDialer();
         RasPhoneBook allUsersPhoneBook = new RasPhoneBook();
         try
         {
             allUsersPhoneBook.Open();
             if (allUsersPhoneBook.Entries.Contains(delVpnName))
             {
                 allUsersPhoneBook.Entries.Remove(delVpnName);
             }
         }
         catch (Exception ex)
         {
             MessagePipe.ExcuteWriteMessageEvent("删除指定VPN名称异常:" + ex.Message.ToString(), Color.Green, true);
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// 游览按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tourbtn_Click(object sender, EventArgs e)
        {
            keywordsList.Clear();
            ////从文本读取关键词
            using (System.IO.StreamReader sr = new System.IO.StreamReader("F:\\phicommwork\\斐讯大数据文档\\游戏画像\\百度指数\\gamekeyword.txt", Encoding.GetEncoding("GB2312")))
            {
                string str;
                while ((str = sr.ReadLine()) != null)
                {
                    keywordsList.Add(str);
                }
            }
            keywordsList = keywordsList.Distinct().ToList();
            MessagePipe.ExcuteWriteMessageEvent("取到关键词" + keywordsList.Count + "条", 0);
            Thread thread = new Thread(new ThreadStart(SubThread));

            thread.IsBackground = true;
            thread.Start();
            flag = 0;
            this.Excute();
        }
Exemplo n.º 12
0
        /// <summary>
        /// 尝试断开VPN(指定VPN名称)
        /// </summary>
        /// <param name="disConnVpnName">连接的vpn名称</param>
        /// <returns>返回执行结果,释放成功true,释放失败false</returns>
        public bool TryDisConnectVPN(string disConnVpnName)
        {
            bool     result    = false;
            DateTime startTime = DateTime.Now;
            string   linkInfo  = string.Empty;

            try
            {
                string args = string.Format(@"{0} /d", disConnVpnName);

                ProcessStartInfo myProcess = new ProcessStartInfo(this.vpnProcess, args);

                myProcess.CreateNoWindow = true;

                myProcess.UseShellExecute        = false;
                myProcess.RedirectStandardOutput = true;
                var excuteResult = Process.Start(myProcess);
                linkInfo = excuteResult.StandardOutput.ReadToEnd();
                linkInfo = linkInfo.Replace("\n", string.Empty);
                if (!linkInfo.Contains("没有连接") && linkInfo.Contains("命令已完成"))
                {
                    result = true;
                }

                MessagePipe.ExcuteWriteMessageEvent("释放结果:" + linkInfo, Color.Green, true);
            }
            catch (Exception ex)
            {
                string msg = disConnVpnName + "断开VPN异常" + ex;
                MessagePipe.ExcuteWriteMessageEvent(msg, Color.Red, true);
            }
            finally
            {
                ////记录交互日志
                string request = "VPN通道名称" + disConnVpnName + ";VPN地址:" + this.vpnIP + ";VPN账号:" + this.userName;
                RecordLog.RecordInteractionLog(this.userName, "断开VPN连接", request, linkInfo, DateTime.Now.Subtract(startTime), this.vpnIP);
            }

            return(result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 子线程
        /// </summary>
        private void SubThread()
        {
            while (true)
            {
                try
                {
                    MessagePipe.ExcuteWriteMessageEvent("处理标志为:" + flag, 0);
                    if (flag >= 1)
                    {
                        if (content.Contains("无"))
                        {
                            ////说明没有释放
                            try
                            {
                                Fiddler.FiddlerApplication.Shutdown();
                            }
                            catch (Exception ex)
                            {
                                MessagePipe.ExcuteWriteMessageEvent("线程释放fillder发生异常:" + ex.Message, 1);
                            }
                        }

                        flag = 0;
                        this.Excute();
                    }
                }
                catch (Exception ex)
                {
                    MessagePipe.ExcuteWriteMessageEvent("子线程异常:" + ex.Message.ToString(), 0);
                }
                finally
                {
                    MessagePipe.ExcuteWriteMessageEvent("线程休眠15秒", 0);
                    Thread.Sleep(15000);
                }
            }
        }
Exemplo n.º 14
0
        /// <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);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 抓取指数
        /// </summary>
        public void ExceuteCrawIndex()
        {
            try
            {
                List <string> keywordsList = new List <string>();
                ////从文本读取关键词
                using (System.IO.StreamReader sr = new System.IO.StreamReader("F:\\amekeyword.txt", Encoding.GetEncoding("GB2312")))
                {
                    string str;
                    while ((str = sr.ReadLine()) != null)
                    {
                        keywordsList.Add(str);
                    }
                }

                MessagePipe.ExcuteWriteMessageEvent("取到关键词" + keywordsList.Count + "条", 0);
                ////开始遍历关键词
                foreach (string keyword in keywordsList)
                {
                    try
                    {
                        MessagePipe.ExcuteWriteMessageEvent("开始处理关键词【" + keyword + "】", 0);
                        HttpRequestParam param    = new HttpRequestParam();
                        string           tempword = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("GB2312"));
                        tempword                = tempword.ToUpper();
                        param.URL               = string.Format("http://index.baidu.com/?tpl=crowd&word={0}", tempword);
                        param.Method            = "get";
                        param.AllowAutoRedirect = false;
                        param.IsIEProxy         = true;
                        param.Cookie            = this.cookie;
                        param.Timeout           = 7 * 1000;
                        param.UserAgent         = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36";
                        param.ResultType        = ResultType.String;
                        HttpResult result   = HttpHelper.GetHttpRequestData(param);
                        String     temphtml = result.Html;
                        temphtml = Regex.Replace(temphtml, @"\r|\n|\s|\t", string.Empty, RegexOptions.IgnoreCase);
                        Regex  regextemp   = new Regex("PPval.ppt=\'(?<str>.*?)\',");
                        Match  matchresult = regextemp.Match(temphtml);
                        string tempstr     = matchresult.Groups["str"].Value;
                        tempstr += "&res2=";
                        ////拼凑字符串,进行解析
                        string temprefer = param.URL;
                        param.Referer = temprefer;
                        param.URL     = string.Format("http://index.baidu.com/Interface/Social/getSocial/?res={0}", tempstr);
                        param.Header.Add("X-Requested-With", "XMLHttpRequest");
                        result = HttpHelper.GetHttpRequestData(param);
                        string jsonstr = result.Html;
                        jsonstr     = jsonstr.Replace("\"", string.Empty);
                        regextemp   = new Regex("str_age:\\{(?<age>.*?)\\},str_sex:\\{(?<sex>.*?)\\}");
                        matchresult = regextemp.Match(jsonstr);
                        string        ageregion = matchresult.Groups["age"].Value;
                        string        sexstr    = matchresult.Groups["sex"].Value;
                        List <string> agelist   = ageregion.Split(',').ToList();
                        List <string> sexlist   = sexstr.Split(',').ToList();
                        ////解析数据
                        string content = string.Empty;
                        foreach (string tempage in agelist)
                        {
                            List <string> tempageList = tempage.Split(':').ToList();
                            content += tempageList[1] + "  ";
                        }

                        foreach (string tempsex in sexlist)
                        {
                            List <string> tempsexlist = tempsex.Split(':').ToList();
                            content += tempsexlist[1] + "  ";
                        }

                        ////追加到txt
                        WriteTxt.WriteAppendTxt("F:\\\baidu.txt", content);
                        MessagePipe.ExcuteWriteMessageEvent("关键词【" + keyword + "】指数数据添加" + content, 0);
                    }
                    catch (Exception ex)
                    {
                        MessagePipe.ExcuteWriteMessageEvent("处理关键词【" + keyword + "】发生异常:" + ex.Message, 1);
                    }
                }
            }
            catch (Exception ex)
            { }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 数据返回前
        /// </summary>
        /// <param name="oSession"></param>
        private void FiddlerApplication_BeforeResponse(Session oSession)
        {
            if (oSession.fullUrl.Contains("index.baidu.com/Interface/Social/getSocial"))
            {
                try
                {
                    byte[] te      = oSession.ResponseBody;
                    byte[] dd      = Decompress(te);
                    string jsonstr = System.Text.Encoding.GetEncoding("utf-8").GetString(dd);
                    jsonstr = jsonstr.Replace("\"", string.Empty);
                    Regex         regextemp   = new Regex("str_age:\\{(?<age>.*?)\\},str_sex:\\{(?<sex>.*?)\\}");
                    Match         matchresult = regextemp.Match(jsonstr);
                    string        ageregion   = matchresult.Groups["age"].Value;
                    string        sexstr      = matchresult.Groups["sex"].Value;
                    List <string> agelist     = ageregion.Split(',').ToList();
                    List <string> sexlist     = sexstr.Split(',').ToList();
                    ////解析数据
                    content = "";
                    if (string.IsNullOrEmpty(keyword))
                    {
                        return;
                    }

                    content += keyword + "  ";
                    foreach (string tempage in agelist)
                    {
                        List <string> tempageList = tempage.Split(':').ToList();
                        content += tempageList[1] + "  ";
                    }

                    foreach (string tempsex in sexlist)
                    {
                        List <string> tempsexlist = tempsex.Split(':').ToList();
                        content += tempsexlist[1] + "  ";
                    }

                    ////追加到txt
                    WriteTxt.WriteAppendTxt("F:\\phicommwork\\斐讯大数据文档\\游戏画像\\百度指数\\baidu.txt", content);
                    MessagePipe.ExcuteWriteMessageEvent("添加数据" + content, 0);
                    content = string.Empty;
                    keyword = string.Empty;
                    Monitor.Enter(oAllSessions);
                    oAllSessions.Clear();
                    Monitor.Exit(oAllSessions);
                }
                catch (Exception ex)
                {
                    MessagePipe.ExcuteWriteMessageEvent("捕获到需要的请求,但发生异常:" + ex.Message, 1);
                }
                try
                {
                    Fiddler.FiddlerApplication.Shutdown();
                }
                catch (Exception ex)
                {
                    MessagePipe.ExcuteWriteMessageEvent("释放fillder发生异常:" + ex.Message, 1);
                }
            }
            else
            {
                content = "无";
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 连接
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void BtnLinkVPN_Click(object sender, EventArgs e)
        {
            if (this.ListViewVpnShow.SelectedItems.Count > 0)
            {
                try
                {
                    ////发送跳出指令,认定IP被封
                    SignalControl.Issuspend = true;

                    ////令ListView不可以选择
                    this.ListViewVpnShow.Enabled = false;

                    //////

                    ////ListViewItem viewItem = this.ListViewVpnShow.FocusedItem;
                    ////MVPNServer vpnServer = new MVPNServer();
                    ////vpnServer.Provider = viewItem.Text;
                    ////vpnServer.Area = viewItem.SubItems[1].Text.ToString();
                    ////vpnServer.Line = viewItem.SubItems[2].Text.ToString();
                    ////vpnServer.Address = viewItem.SubItems[3].Text.ToString();
                    ////if (this.linkThread == null)
                    ////{
                    ////    this.linkThread = new BetterThread();
                    ////}

                    ////this.linkThread.ExcuteThreadInstance(
                    ////    () =>
                    ////    {
                    ////        if (flagThreadWorking)
                    ////        {
                    ////            flagThreadWorking = false;
                    ////            ////删除现有连接,建立新的连接
                    ////            ////断开VPN
                    ////            if (VpnControlThread.VpnHelper != null)
                    ////            {
                    ////                ////还原原来使用的IP状态

                    ////                ////断开之前判断是否处于连接状态,如果处于连接状态无法删除
                    ////                MessagePipe.ExcuteShowIpInfoEvent(vpnServer.Address);
                    ////                List<string> islinkingVpn = VpnControlThread.VpnHelper.GetCurrentConnectingVPNNames();
                    ////                if (islinkingVpn == null || islinkingVpn.Count == 0)
                    ////                {
                    ////                    VpnControlThread.VpnHelper.TryDisConnectVPN();
                    ////                    VpnControlThread.VpnHelper.TryDeleteVPN();
                    ////                    MessagePipe.ExcuteShowLinkInfoEvent("未连接");
                    ////                    //////建立新的连接
                    ////                    bool linkResult = this.vpnControlThread.IslinkVpnServer(VpnControlThread.VpnAccount, vpnServer);
                    ////                    SignalControl.Issuspend = true;

                    ////                    SignalControl.WaitSignal.WaitOne();
                    ////                    if (linkResult)
                    ////                    {
                    ////                        this.BulletMessage("人工手动替换VPN服务器成功");
                    ////                        MessagePipe.ExcuteShowLinkInfoEvent("连接成功");
                    ////                    }
                    ////                    else
                    ////                    {
                    ////                        this.BulletMessage("人工手动替换VPN服务器失败,请重新选一个!!!");
                    ////                        MessagePipe.ExcuteShowLinkInfoEvent("未连接");
                    ////                    }
                    ////                }
                    ////            }
                    ////            else
                    ////            {
                    ////                this.BulletMessage("有正在连接中的请求,请稍后替换!!!");
                    ////            }
                    ////        }
                    ////    },
                    ////    null,
                    ////    null,
                    ////    TimeSpan.FromSeconds(1));
                }
                catch (Exception ex)
                {
                    MessagePipe.ExcuteWriteMessageEvent("手动替换VPN异常" + ex.Message.ToString(), Color.Red, true);
                }
            }
            else
            {
                MessageBox.Show("请选中要替换的VPN服务器");
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 重写方法
        /// </summary>
        protected override void ExcuteMethod()
        {
            while (true)
            {
                try
                {
                    bool isneedLock = true;
                    MessagePipe.ExcuteWriteMessageEvent("517VPN客户端启动成功", Color.Green, false);
                    VpnInfo vpnInfo = new VpnInfo();

                    ////获取账号
                    this.GetVpnAccount(ref isneedLock);
                    if (VpnAccount != null && !string.IsNullOrEmpty(VpnAccount.KeyID))
                    {
                        MessagePipe.ExcuteWriteMessageEvent("517VPN客户端获取到账号" + VpnAccount.Account, Color.Green, false);
                        ////马上锁定账号,锁定成功过,才允许使用这个账号
                        bool lockAccountResult = vpnInfo.UpdateVpnAccountState(VpnAccount);
                        if (lockAccountResult || !isneedLock)
                        {
                            MessagePipe.ExcuteShowAccountInfoEvent(VpnAccount.Account);
                            MessagePipe.ExcuteWriteMessageEvent("517VPN客户端锁定账号:" + VpnAccount.Account + "成功", Color.Green, false);

                            ////清空一下加载的数据
                            MessagePipe.ExcuteDelVpnServerInfoEvent("clear");

                            ////加载出所有可用的VPN服务器信息,先拿使用服务器为本机的IP
                            List <MVPNServer> tempExceptionVpn = vpnInfo.GetLocalUsedVpnServer(VpnAccount.Provider);
                            ProductVpnServers.AddRange(tempExceptionVpn);

                            List <MVPNServer> tempValidVpn = this.GetAllValidVpnServer(VpnAccount.Provider);
                            ProductVpnServers.AddRange(tempValidVpn);

                            ////因为有可能因为异常退出,导致IP一直被占用,所以首先取使用IP为自己服务器的IP
                            if (ProductVpnServers != null && ProductVpnServers.Count > 0)
                            {
                                MessagePipe.ExcuteBindVpnServerInfoEvent(ProductVpnServers);

                                ////锁定成功,取一个可用的VPN服务器建立连接(人工切换IP会有影响,)
                                foreach (var tempVpn in ProductVpnServers)
                                {
                                    TrackID.GetInstance("517VPN");

                                    ////////接收到暂停指令
                                    ////if (SignalControl.Issuspend)
                                    ////{
                                    ////    ////等待解锁指令
                                    ////    SignalControl.WaitSignal.WaitOne();
                                    ////}

                                    VpnServer = tempVpn;
                                    MessagePipe.ExcuteShowIpInfoEvent(tempVpn.Address);
                                    MessagePipe.ExcuteShowLinkInfoEvent("连接中...");

                                    ////IP独占成功,方可连接
                                    if (vpnInfo.UpdateVpnUseStatu(tempVpn) || tempVpn.UsingServer == new GetIP().GetLocalIp("本地连接"))
                                    {
                                        string msg           = string.Empty;
                                        bool   connectResult = this.IslinkVpnServer(VpnAccount, tempVpn);
                                        if (connectResult)
                                        {
                                            MessagePipe.ExcuteWriteMessageEvent("517客户端连接VPN:" + tempVpn.Address + "成功", Color.Green, false);
                                            MessagePipe.ExcuteShowLinkInfoEvent("连接成功");

                                            ////建立连接成功过后,调用业务组件,如果业务组件需要更换VPN服务器,则删除现有连接,重新建立新连接
                                            bool result = this.InvokeIpMonitor();
                                            if (result)
                                            {
                                                ////需要替换IP,还原数据状态
                                                vpnInfo.UpdateVpnIsValid(tempVpn);
                                                MessagePipe.ExcuteWriteMessageEvent("检测到" + tempVpn.Address + "被封,需要替换IP", Color.Green, false);
                                            }
                                        }
                                        else
                                        {
                                            msg = tempVpn.Provider + "|" + tempVpn.Address;
                                            vpnInfo.UpdateVpnLinkStatu(tempVpn);
                                            MessagePipe.ExcuteWriteMessageEvent(msg + "连接失败", Color.Red, false);
                                        }

                                        msg = tempVpn.Provider + "|" + tempVpn.Address;
                                        MessagePipe.ExcuteDelVpnServerInfoEvent(msg);

                                        ////连接失败,删除连接
                                        if (VpnControlThread.VpnHelper != null)
                                        {
                                            ////退出之前关闭VPN
                                            bool disConnectResult = VpnControlThread.VpnHelper.TryDisConnectVPN();
                                            VpnControlThread.VpnHelper.TryDeleteVPN();
                                            MessagePipe.ExcuteShowLinkInfoEvent("未连接");
                                        }
                                    }
                                }

                                ////表明这一轮可用IP已经使用完了,所以清空一下
                                ProductVpnServers.Clear();
                            }
                        }
                        else
                        {
                            MessagePipe.ExcuteWriteMessageEvent("517VPN客户端没有锁定到账号,休眠40秒", Color.Red, true);
                            ////锁定失败,休眠一分钟
                            Thread.Sleep(TimeSpan.FromSeconds(40));
                        }
                    }
                    else
                    {
                        MessagePipe.ExcuteWriteMessageEvent("517VPN客户端没有获取到账号,休眠40秒", Color.Red, true);
                        ////锁定失败,休眠一分钟
                        Thread.Sleep(TimeSpan.FromSeconds(40));
                    }
                }
                catch (Exception ex)
                {
                    LogManager.Log.WriteException(new AppException("517VPN客户端主流程异常", ex, ExceptionLevel.Error));
                    MessagePipe.ExcuteWriteMessageEvent("517VPN主流程异常" + ex.Message.ToString(), Color.Red, false);
                }
                finally
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
        }