Click here to Skip to main content
15,896,269 members
Articles / Programming Languages / C#

Internet Magic (Proxy Server) Windows Application

Rate me:
Please Sign up or sign in to vote.
3.00/5 (8 votes)
10 Apr 2010CPOL3 min read 68.7K   8.8K   38  
Windows application which creates a proxy server to share Internet over any TCP/IP network
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Diagnostics;
using System.Windows.Forms;
using internet_magic.bandwidth;

namespace internet_magic
{   /// <summary>
    /// Windows form class for main GUI.
    /// </summary>
    public partial class int_magic : Form
    {
        public int_magic(string file)
        {
            ipmon = new ip_monitor(this, file);
            
		}
        /// <summary>
        /// Initialise an instance of main GUI. 
        /// </summary>
        public int_magic(Program parent)
        {
            
            InitializeComponent();
            button12.Image = Properties.Resources.MONI1;
            chartControlForm1.InitChart();
            chartControlForm2.InitChart();
            m_Parent = parent;
            string dir = Environment.CurrentDirectory;
            if (!dir.Substring(dir.Length - 1, 1).Equals(@"\"))
                dir += @"\";
            int_magic ipm = new int_magic(dir + "IPmon.xml");
            if (System.IO.File.Exists(ipm.ipmon.File))
                ipm.ipmon.LoadData();
            
                
            
            if (ipm.ipmon.sList.IsstsPresent("on"))
            {
                ipm.ipmon.sList.RemoveItem("on");
                
            }
            ipm.ipmon.Savests("off");
           

        }
        
        /// <summary>
        /// Initialise on click of add listeners button. 
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            add_lisnr frmal = new add_lisnr(prx);
            frmal.Show();
        }
        /// <summary>
        /// Initialise on click of Stop listeners button. 
        /// </summary>
        private void button2_Click(object sender, EventArgs e)
        {

            
            
            if (prx.ListenerCount == 0)
            {
                MessageBox.Show("No Active Listeners!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                while (prx.ListenerCount != 0)
                {
                    prx.ShowDelListener();
                }
                MessageBox.Show("All Listeners Stopped.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                
            }
        }

        /// <summary>
        /// Initialise on click of uptime button. 
        /// </summary>
        private void button3_Click(object sender, EventArgs e)
        {
           
            //TimeSpan uptime = DateTime.Now.Subtract(Program.StartTime);
            
            String datet = Program.StartTime.ToString();
            MessageBox.Show(datet, "Uptime", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        /// <summary>
        /// Initialise on click of web filter button. 
        /// </summary>
        private void button4_Click(object sender, EventArgs e)
        {
            web_filter frmal = new web_filter(prx);
            frmal.Show();
        }
        /// <summary>
        /// Initialise on click of add user button. 
        /// </summary>
        private void button5_Click(object sender, EventArgs e)
        {
            adduser frmaddu = new adduser(prx);
            frmaddu.Show();
        }
        /// <summary>
        /// Initialise on click of remove user button. 
        /// </summary>
        private void button6_Click(object sender, EventArgs e)
        {
            remuser frmremu = new remuser(prx);
            frmremu.Show();
        }
        /// <summary>
        /// Initialise on click of show user button. 
        /// </summary>
        private void button7_Click(object sender, EventArgs e)
        {
            userlist frmremu = new userlist(prx);
            frmremu.Show();
        }
        /// <summary>
        /// Initialise on click of Register IP button. 
        /// </summary>
        private void button8_Click(object sender, EventArgs e)
        {
            IP_filter frmal = new IP_filter(prx);
            frmal.Show();
        }
        
        /// <summary>
        /// Initialise on click of Active listeners button. 
        /// </summary>
        private void button10_Click(object sender, EventArgs e)
        {
            act_listall frmal = new act_listall(prx);
            frmal.Show();
        }
        /// <summary>
        /// Initialise on click of Information button. 
        /// </summary>
        private void button9_Click(object sender, EventArgs e)
        {
            AboutBox1 frmal = new AboutBox1();
            frmal.Show();
            
        }
        
        private NetworkAdapter[] adapters;
        private NetworkMonitor monitor;
        /// <summary>
        /// Used to Display bandwidth usage. 
        /// </summary>
        private void int_magic_Load(object sender, EventArgs e)
        {
            monitor = new NetworkMonitor();
            this.adapters = monitor.Adapters;

            if (adapters.Length == 0)
            {
                this.adp_list.Enabled = false;

                MessageBox.Show("No network adapters found on this computer.", "APPLICATION QUITTING...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            this.adp_list.Items.AddRange(this.adapters);
            chartControlForm1.OpenType = internet_magic.ChartControl.ChartControlOpenType.Bar;
            chartControlForm1.RefreshControl();
            chartControlForm2.OpenType = internet_magic.ChartControl.ChartControlOpenType.Bar;
            chartControlForm2.RefreshControl();
            
        }
        /// <summary>
        /// Initialise adapter list box. 
        /// </summary>
        private void adp_list_SelectedIndexChanged(object sender, EventArgs e)
        {
            monitor.StopMonitoring();
            monitor.StartMonitoring(adapters[this.adp_list.SelectedIndex]);
            this.TimerCounter.Start();
        }

      
       /// <summary>
        /// Define timercount data and propeties. 
        /// </summary>
        private void TimerCounter_Tick_1(object sender, EventArgs e)
        {
            double ValueAdd, ValueAdd1;
            NetworkAdapter adapter = this.adapters[this.adp_list.SelectedIndex];
            ValueAdd = Convert.ToDouble(adapter.DownloadSpeedKbps/1.5);
            ValueAdd1 = Convert.ToDouble(adapter.UploadSpeedKbps/1.5);
            chartControlForm1.AddValue((float)ValueAdd, 0);
            chartControlForm2.AddValue((float)ValueAdd1, 1);
            this.LableDownloadValue.Text = String.Format("{0:n} kbps", adapter.DownloadSpeedKbps);
            this.LabelUploadValue.Text = String.Format("{0:n} kbps", adapter.UploadSpeedKbps);
        }
        /// <summary>
        /// Gets the parent object of this ProxyConfig class.
        /// </summary>
        /// <value>An instance of the Proxy class.</value>
        public Program prx
        {
            get
            {
                return m_Parent;
            }
        }

        /// <summary>Holds the value of the Parent property.</summary>
        private Program m_Parent;

        

        private void button11_Click(object sender, EventArgs e)
        {
            clnt_log frmal = new clnt_log();
            frmal.Show();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            string dir = Environment.CurrentDirectory;
            if (!dir.Substring(dir.Length - 1, 1).Equals(@"\"))
                dir += @"\";
            int_magic ipm = new int_magic(dir + "IPmon.xml");
            if (System.IO.File.Exists(ipm.ipmon.File))
                ipm.ipmon.LoadData();
            if (ipm.ipmon.sList.IsstsPresent("on"))
            {
                ipm.ipmon.sList.RemoveItem("on");
                ipm.ipmon.Savests("off");
                button12.Image = Properties.Resources.MONI1;
                MessageBox.Show("Network computer monitoring OFF.", "MONITORING OFF", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            else if (ipm.ipmon.sList.IsstsPresent("off"))
            {
                ipm.ipmon.sList.RemoveItem("off");
                ipm.ipmon.Savests("on");
                button12.Image = Properties.Resources.MONI;
                MessageBox.Show("Network computer monitoring ON.", "MONITORING ON", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
        public ip_monitor ipmon
        {
            get
            {
                return m_ipmon;
            }
            set
            {
                m_ipmon = value;
            }
        }
        private ip_monitor m_ipmon;

        

        private void button13_Click(object sender, EventArgs e)
        {
            ipmonitor frmal = new ipmonitor();
            frmal.Show();
        }
       
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions