public TcpClient Connect(string host, int StartPort, int timeOut)
        {
            var newclient = new TcpClient();
            var state     = new isTCPPortOpen
            {
                Client  = newclient,
                tcpOpen = true
            };
            IAsyncResult ar = newclient.BeginConnect(host, StartPort, AsyncCallback, state);

            state.tcpOpen = ar.AsyncWaitHandle.WaitOne(timeOut, false);

            if (state.tcpOpen == true)
            {
                richTextBox2.Text = richTextBox2.Text + "\n TCP Port is Open and the Port Number Is" + StartPort.ToString();
                Application.DoEvents();
            }
            if (state.tcpOpen == false)
            {
                richTextBox1.Text = richTextBox1.Text + "\n TCP Port" + StartPort.ToString() + "is not avaolable for access";

                Application.DoEvents();
                throw new Exception();
            }

            return(newclient);
        }
Ejemplo n.º 2
0
        public TcpClient Connect(string host, int StartPort, int timeOut)
        {
            var newclient = new TcpClient();
            var state     = new isTCPPortOpen
            {
                Client = newclient, tcpOpen = true
            };

            //Asynchronous request for the ports to check whether its open or not.

            IAsyncResult ar = newclient.BeginConnect(host, StartPort, AsyncCallback, state);

            state.tcpOpen = ar.AsyncWaitHandle.WaitOne(timeOut, false);

            if (state.tcpOpen == true)
            {
                //Find for vulnerable ports.

                richTextBox2.Text = richTextBox2.Text + "\n TCP Port is open and the port number is " + StartPort.ToString();
                Application.DoEvents();

                //Prinitng the data immediately.
            }
            if (state.tcpOpen == false)
            {
                ////Find for non-vulnerable ports.

                richTextBox2.Text = richTextBox1.Text + "\n TCP Port " + StartPort.ToString() + " is not available for access.";
                Application.DoEvents();

                //Prinitng the data immediately.

                throw new Exception();
            }
            return(newclient);
        }