Esempio n. 1
0
        /// <summary>
        /// Generates a report on the selected IP address; pretty much just formats everything found
        /// in its IPObj object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void infoButton_Click(object sender, EventArgs e)
        {
            int    rowIdx = 0;
            string ip     = null;

            fireBwall.Utils.IPObj tmp;

            if (blockedIPList.SelectedRows.Count <= 0)
            {
                ip  = potentialIPBox.SelectedItem.ToString();
                tmp = detector.potentials[IPAddr.Parse(ip)];
            }
            else if (potentialIPBox.SelectedIndex < 0)
            {
                rowIdx = blockedIPList.SelectedCells[0].RowIndex;
                ip     = blockedIPList["IP", rowIdx].Value.ToString();
                tmp    = detector.data.BlockCache[IPAddr.Parse(ip)];
            }
            else
            {
                return;
            }

            // go generate the report
            Report report = new Report();

            report.GenerateReport(tmp);
        }
Esempio n. 2
0
        public void IPAddrSerialization()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(IPAddr));
            MemoryStream  ms         = new MemoryStream();
            IPAddr        outAddr    = IPAddr.Parse("192.168.1.1");

            serializer.Serialize(ms, outAddr);
            ms.Position = 0;
            IPAddr inAddr = (IPAddr)serializer.Deserialize(ms);

            Assert.AreEqual("192.168.1.1", inAddr.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// removes the blocked IP address from the table and the block cache
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeBlockedButton_Click(object sender, EventArgs e)
        {
            if (blockedIPList.SelectedRows.Count < 0)
            {
                return;
            }

            int    rowIdx = blockedIPList.SelectedCells[0].RowIndex;
            string ip     = blockedIPList["IP", rowIdx].Value.ToString();

            // remove it from the block cache
            detector.data.BlockCache.Remove(IPAddr.Parse(ip));
            blockedIPList.Rows.RemoveAt(rowIdx);
        }
Esempio n. 4
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     try
     {
         if (listBox1.SelectedItem != null)
         {
             string i  = (string)listBox1.SelectedItem;
             IPAddr ip = IPAddr.Parse(i.Split(' ')[2]);
             cache.Remove(ip);
             saap.UpdateCache(cache);
             cache = saap.GetCache();
             saap_UpdatedArpCache();
         }
     }
     catch { }
 }
Esempio n. 5
0
        /// <summary>
        /// handles the block button action; adds the selected IP address
        /// to the block list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void blockButton_Click(object sender, EventArgs e)
        {
            if (potentialIPBox.SelectedIndex < 0)
            {
                return;
            }

            String ip = potentialIPBox.SelectedItem.ToString();

            // add it to the data block cache
            detector.data.BlockCache.Add(IPAddr.Parse(ip), detector.potentials[IPAddr.Parse(ip)]);
            // remove it from the potential list
            potentialIPBox.Items.Remove(ip);
            detector.potentials.Remove(IPAddr.Parse(ip));
            // add it to the block list
            blockedIPList.Rows.Add(ip);
        }
Esempio n. 6
0
        /// <summary>
        /// Handles the IP add button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addButton_Click(object sender, EventArgs e)
        {
            // if the given string is a valid IPv4 addr.
            // IPAddress.TryParse is broken.
            if (regIP.IsMatch(addField.Text))
            {
                IPAddr t = IPAddr.Parse(addField.Text);
                blockcache.Add(new BlockedIP(t, DateTime.UtcNow, "User added"));

                // update the module blockcache and update the table
                UpdateBlockedCache();
                RebuildTable();

                // consume input
                addField.Text = "";
            }
        }
Esempio n. 7
0
        public void DictionaryofIPAddrSerialization()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary <IPAddr, IPAddr>));
            MemoryStream  ms         = new MemoryStream();
            IPAddr        outAddr    = IPAddr.Parse("192.168.1.1");
            SerializableDictionary <IPAddr, IPAddr> list = new SerializableDictionary <IPAddr, IPAddr>();

            list.Add(outAddr, outAddr);
            serializer.Serialize(ms, list);
            ms.Position = 0;
            SerializableDictionary <IPAddr, IPAddr> inAddr = (SerializableDictionary <IPAddr, IPAddr>)serializer.Deserialize(ms);

            foreach (KeyValuePair <IPAddr, IPAddr> pair in inAddr)
            {
                Assert.AreEqual("192.168.1.1", pair.Key.ToString());
                Assert.AreEqual("192.168.1.1", pair.Value.ToString());
            }
        }
Esempio n. 8
0
        public void ListofIPAddrSerialization()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List <IPAddr>));
            MemoryStream  ms         = new MemoryStream();
            IPAddr        outAddr    = IPAddr.Parse("192.168.1.1");
            List <IPAddr> list       = new List <IPAddr>();

            list.Add(outAddr);
            list.Add(outAddr);
            list.Add(outAddr);
            serializer.Serialize(ms, list);
            ms.Position = 0;
            List <IPAddr> inAddr = (List <IPAddr>)serializer.Deserialize(ms);

            Assert.AreEqual("192.168.1.1", inAddr[0].ToString());
            Assert.AreEqual("192.168.1.1", inAddr[1].ToString());
            Assert.AreEqual("192.168.1.1", inAddr[2].ToString());
        }
Esempio n. 9
0
        public void SerializableDictionaryOfIPAddrSerialization()
        {
            XmlSerializer             serializer = new XmlSerializer(typeof(SerializableList <IPAddr>));
            MemoryStream              ms         = new MemoryStream();
            IPAddr                    outAddr    = IPAddr.Parse("192.168.1.1");
            SerializableList <IPAddr> list       = new SerializableList <IPAddr>();

            list.Add(outAddr);
            list.Add(outAddr);
            serializer.Serialize(ms, list);
            ms.Position = 0;
            SerializableList <IPAddr> inAddr = (SerializableList <IPAddr>)serializer.Deserialize(ms);

            foreach (IPAddr ip in inAddr)
            {
                Assert.AreEqual("192.168.1.1", ip.ToString());
                Assert.AreEqual("192.168.1.1", ip.ToString());
            }
        }