コード例 #1
0
        private async void GetIPS_Click(object sender, EventArgs e)
        {
            var response = await client.GetAsync($"{SERVER_ADDRESS}/{GET_IPS_LIST}");

            var ip_list = JsonConvert.DeserializeObject <List <Ip> >(await response.Content.ReadAsStringAsync());

            IPListView.SetObjects(ip_list);
        }
コード例 #2
0
        private async void Checkip_ClickAsync(object sender, EventArgs e)
        {
            var jsonIPS       = JsonConvert.SerializeObject((Ip)IPListView.SelectedObject);
            var stringContent = new StringContent(jsonIPS, UnicodeEncoding.UTF8, "application/json");
            var response      = await client.PostAsync($"{SERVER_ADDRESS}/{CHECK_IP}", stringContent);

            var ip_list = JsonConvert.DeserializeObject <List <Ip> >(await response.Content.ReadAsStringAsync());

            IPListView.SetObjects(ip_list);
        }
コード例 #3
0
        private void DisplayArticles()
        {
            Guid session = new Guid();

            //we've never seen this user before or they've cleared their cookies
            if (Request.Cookies["session"] != null && Guid.TryParse(Request.Cookies["session"].Value, out session))
            {
                int userID = Auth.checkSession(session);
                if (userID != 0)
                {
                    List <string> IPList = RatingHelper.GetImprovementProgramList();

                    List <Tuple <string, double> > RatedArticles = RatingHelper.GetAllRatedArticles(userID, "rated", 0, 10);


                    DataTable dt = new DataTable();
                    dt.Columns.Add("Article");
                    dt.Columns.Add("Rated", System.Type.GetType("System.String"));
                    dt.Columns.Add("RatedStyle", System.Type.GetType("System.String"));

                    foreach (string article in IPList)
                    {
                        bool found = false;
                        foreach (Tuple <string, double> ratedArt in RatedArticles)
                        {
                            if (article == ratedArt.Item1)
                            {
                                DataRow dr = dt.NewRow();
                                //encode
                                dr["Article"]    = Server.HtmlEncode(article);
                                dr["Rated"]      = "Rated";
                                dr["RatedStyle"] = "Rated";

                                dt.Rows.Add(dr);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            DataRow dr = dt.NewRow();
                            //encode
                            dr["Article"]    = Server.HtmlEncode(article);
                            dr["Rated"]      = "Not Yet";
                            dr["RatedStyle"] = "NotRated";

                            dt.Rows.Add(dr);
                        }
                    }
                    dt.DefaultView.Sort   = "Article";
                    IPListView.DataSource = dt.DefaultView;
                    IPListView.DataBind();
                }
            }
        }
コード例 #4
0
        private void logCheck(object sender, FileSystemEventArgs e)
        {
            try
            {
                if (e.Name.StartsWith("ex"))
                {
                    if (DateTime.Now.Minute >= lastCheck.Minute + 5)
                    {
                        if (lastCheck.Hour == DateTime.Now.Hour)
                        {
                            logFileBefore = logFileNow;
                            logFileNow    = e;
                        }
                        else
                        {
                            logFileBefore = logFileNow;
                        }
                        lastCheck = DateTime.Now;

                        System.IO.StreamReader file = new System.IO.StreamReader(e.FullPath);

                        var aLine = file.ReadLine();

                        string[] lineSplit = null;

                        while (aLine != null)
                        {
                            if (aLine.Contains(DateTime.Now.Year.ToString()))
                            {
                                lineSplit = aLine.Split(' ');

                                if (lineSplit[9].Contains("Invalid+Username+or+Password"))
                                {
                                    if (totalIpDictionary.ContainsKey(lineSplit[2]))
                                    {
                                        totalIpDictionary.TryGetValue(lineSplit[2], out int oldValue);
                                        totalIpDictionary[lineSplit[2]] = oldValue + 1;
                                    }
                                    else
                                    {
                                        totalIpDictionary.Add(lineSplit[2], 1);
                                    }
                                }
                            }

                            aLine = file.ReadLine();
                        }

                        file.Close();

                        string pathToWrite = @"C:\fileCheckerBlockedIPList.txt";

                        System.IO.StreamWriter myFileOpener = new System.IO.StreamWriter(pathToWrite, true);
                        myFileOpener.Close();

                        System.IO.StreamReader myFileReader = new System.IO.StreamReader(pathToWrite);

                        List <string> ipListOnFile = new List <string>();

                        string line = myFileReader.ReadLine();

                        while (line != null)
                        {
                            ipListOnFile.Add(line);
                            line = myFileReader.ReadLine();
                        }
                        myFileReader.Close();

                        System.IO.StreamWriter myFileWriter = new System.IO.StreamWriter(pathToWrite, true);

                        var matches = totalIpDictionary.Where(element => element.Value > 2);
                        for (int j = 0; j < matches.ToList().Count; j++)
                        {
                            if (!ipListOnFile.Contains(matches.ToArray()[j].Key))
                            {
                                totalIPDictionaryToBlock.Add(matches.ToArray()[j].Key, matches.ToArray()[j].Value);
                                myFileWriter.WriteLine(matches.ToArray()[j].Key);
                                FWCtrl fw = new FWCtrl();
                                fw.ipAddToList(matches.ToArray()[j].Key);
                            }
                        }
                        myFileWriter.Close();
                        IPListView.Items.Clear();
                        for (int i = 0; i < totalIPDictionaryToBlock.Count; i++)
                        {
                            string[] bilgiler =
                            {
                                totalIPDictionaryToBlock.Keys.ToArray()[i],
                                DateTime.Now.ToString(),
                                totalIPDictionaryToBlock.Values.ToArray()[i].ToString()
                            };

                            var n = new ListViewItem(bilgiler);
                            IPListView.Items.Add(n);
                            IPListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                        }

                        if (totalIPDictionaryToBlock.Count > 50)
                        {
                            totalIPDictionaryToBlock.Clear();
                        }
                        if (totalIpDictionary.Count > 100)
                        {
                            totalIpDictionary.Clear();
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }