protected void check_close(easy_socket.tcp.Socket_Data sender)
 {
     if (this.checkBox_transmit_close.Checked)
     {
         this.enable_state(false);
         if (sender == this.socket_to_clt)
         {
             this.socket_to_srv.close();
             this.evtConnectedToServer.Reset();
         }
         else
         {
             this.socket_to_clt.close();
         }
     }
     else
     {
         if (sender == this.socket_to_clt)
         {
             this.radioButton_send_to_srv.Checked = true;
             this.radioButton_send_to_clt.Enabled = false;
         }
         else
         {
             this.radioButton_send_to_clt.Checked = true;
             this.radioButton_send_to_srv.Enabled = false;
         }
     }
 }
Esempio n. 2
0
 protected void socket_data_arrival(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_ReceiveDataSocket e)
 {
     if (this.checkBox_rcv_hexa_data.Checked)
     {
         this.textBox_telnet_add(easy_socket.hexa_convert.byte_to_hexa(e.buffer, " ") + " ");
     }
     else
     {
         string strdata = System.Text.Encoding.Default.GetString(e.buffer, 0, e.buffer_size);
         // if telnet protocol
         #region telnet protocol
         if (this.b_telnet_protocol)
         {
             // data to show
             byte[][] reply_array = this.telnet.parse(strdata);
             if (reply_array != null)
             {
                 for (int cnt = 0; cnt <= reply_array.GetUpperBound(0); cnt++)
                 {
                     this.clt.send(reply_array[cnt]);
                 }
             }
         }
         #endregion
         else if (strdata.Length > 0)
         {
             this.textBox_telnet_add(strdata);
         }
     }
 }
        public FormWhois(string ip, bool autofind, string other_server)
        {
            InitializeComponent();
            Tools.GUI.XPStyle.MakeXPStyle(this);

            this.textBox_whois_ip.Text = ip;
            this.radioButton_whois_auto_find.Checked     = autofind;
            this.radioButton_whois_use_following.Checked = !autofind;
            this.textBox_whois_server.Text    = other_server;
            this.textBox_whois_server.Enabled = !autofind;
            this.socket = new easy_socket.tcp.Socket_Data();
            this.socket.event_Socket_Data_Closed_by_Remote_Side    += new easy_socket.tcp.Socket_Data_Closed_by_Remote_Side_EventHandler(socket_closed_by_remote_side);
            this.socket.event_Socket_Data_Connected_To_Remote_Host += new easy_socket.tcp.Socket_Data_Connected_To_Remote_Host_EventHandler(socket_connected_to_remote_host);
            this.socket.event_Socket_Data_DataArrival += new easy_socket.tcp.Socket_Data_DataArrival_EventHandler(socket_data_arrival);
            this.socket.event_Socket_Data_Error       += new easy_socket.tcp.Socket_Data_Error_EventHandler(socket_error);

            this.data_to_send = "";
            this.whois_server = "";

            string filename = System.Windows.Forms.Application.StartupPath + "\\" + WHOIS_SERVER_LIST_FILE;

            this.load_server_list(filename);
            // send whois
            this.button_whois_Click(this, null);
        }
 private void socket_event_Socket_Data_Closed_by_Remote_Side(easy_socket.tcp.Socket_Data sender, EventArgs e)
 {
     this.ConnectionState = PROXY_CONNECTION_STATE.CLOSED;
     this.hevt_remotely_closed.Set();
     if (this.event_ClassProxy_Closed_by_Remote_Side != null)
     {
         this.event_ClassProxy_Closed_by_Remote_Side(this, e);
     }
 }
 private void socket_event_Socket_Data_Error(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_Exception e)
 {
     this.ConnectionState = PROXY_CONNECTION_STATE.CLOSED;
     this.hevt_error.Set();
     if (this.event_ClassProxy_Error != null)
     {
         this.event_ClassProxy_Error(this, e);
     }
 }
 private void socket_event_Socket_Data_Connected_To_Remote_Host(easy_socket.tcp.Socket_Data sender, EventArgs e)
 {
     this.ConnectionState = PROXY_CONNECTION_STATE.CONNECTED;
     this.hevt_connected.Set();
     if (this.event_ClassProxy_Connected_To_Remote_Host != null)
     {
         this.event_ClassProxy_Connected_To_Remote_Host(this, e);
     }
 }
Esempio n. 7
0
 protected void socket_closed_by_remote_side(easy_socket.tcp.Socket_Data sender, EventArgs e)
 {
     this.enable_state(false);
     // return to a new line (split != send and send/receive)
     if (!this.textBox_telnet.Text.EndsWith("\r\n"))
     {
         this.textBox_telnet_add("\r\n");
     }
     this.textBox_telnet_add("Connection closed by remote side.\r\n");
 }
 private void socket_event_Socket_Data_Send_Progress(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_Send_Progress_Socket_Data e)
 {
     if (this.ConnectionState == PROXY_CONNECTION_STATE.READY_TO_SEND_USER_DATA)
     {
         if (this.event_ClassProxy_Send_Progress != null)
         {
             this.event_ClassProxy_Send_Progress(this, e);
         }
     }
 }
Esempio n. 9
0
        public void new_tcp_client(System.Net.Sockets.Socket s, int port)
        {
            System.Net.IPEndPoint ipep = (System.Net.IPEndPoint)s.RemoteEndPoint;

            this.Text = "Remote host (" + ipep.Address.ToString() + ":" + ipep.Port + ") connected on port " + port.ToString();
            clt       = new easy_socket.tcp.Socket_Data(s);
            add_events();
            // no reconnection available: this socket is from server
            this.button_connect.Visible = false;
        }
 private void socket_event_Socket_Data_DataArrival(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_ReceiveDataSocket e)
 {
     this.hevt_data_arrival.Set();
     this.last_data = e.buffer;
     if (this.ConnectionState == PROXY_CONNECTION_STATE.READY_TO_SEND_USER_DATA)
     {
         if (this.event_ClassProxy_DataArrival != null)
         {
             this.event_ClassProxy_DataArrival(this, e);
         }
     }
 }
Esempio n. 11
0
 protected void socket_error(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_Exception e)
 {
     if (this.textBox_telnet.Text != "")
     {
         if (!this.textBox_telnet.Text.EndsWith("\r\n"))
         {
             this.textBox_telnet_add("\r\n");
         }
     }
     this.textBox_telnet_add("Socket Error: " + e.exception.Message + "\r\n");
     this.enable_state(false);
 }
        protected void socket_error(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_Exception e)
        {
            int res = System.Threading.WaitHandle.WaitAny(this.HexaViewWaitHandles);

            if (res == 0) // close event
            {
                return;
            }

            this.add_info("Socket Error: " + e.exception.Message);
            this.check_close(sender);
            this.refresh_data();
            this.evtNotWrittingData.Set();
        }
Esempio n. 13
0
        public void new_tcp_client(string ip, int port, bool force_local_port, int local_port, bool telnet_protocol)
        {
            myip      = ip;
            myport    = port;
            this.Text = "Connected to " + myip + ":" + myport.ToString();
            if (force_local_port)
            {
                try
                {
                    this.Text += " local port:" + local_port.ToString();
                    clt        = new easy_socket.tcp.Socket_Data(1024, local_port);//error are not catch
                }
                catch (Exception e)
                {
                    this.textBox_telnet_add(e.Message + "\r\n");
                    if (e is System.Net.Sockets.SocketException)
                    {
                        System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)e;
                        if (se.ErrorCode == 10048)
                        {
                            // return to a new line (split != send and send/receive)
                            if (!this.textBox_telnet.Text.EndsWith("\r\n"))
                            {
                                this.textBox_telnet_add("\r\n");
                            }
                            this.textBox_telnet_add("Please wait few seconds before retry.\r\n");
                        }
                    }
                    return;
                }
            }
            else
            {
                clt = new easy_socket.tcp.Socket_Data();
            }
            add_events();
            clt.connect(ip, port);

            // for telnet protocol
            #region telnet protocol
            if (telnet_protocol)
            {
                this.set_telnet_protocol(true);
            }
            this.checkBox_telnet.Checked            = telnet_protocol;
            this.checkBox_beep_on_bell.Enabled      = telnet_protocol;
            this.checkBox_send_function_key.Enabled = telnet_protocol;
            this.checkBox_no_buffer.Enabled         = telnet_protocol;
            #endregion
        }
        protected void socket_connected_to_remote_host(easy_socket.tcp.Socket_Data sender, EventArgs e)
        {
            int res = System.Threading.WaitHandle.WaitAny(this.HexaViewWaitHandles);

            if (res == 0) // close event
            {
                return;
            }

            this.evtConnectedToServer.Set();

            this.add_info("Connected to " + sender.RemoteIP + ":" + sender.RemotePort);
            this.refresh_data();
            this.evtNotWrittingData.Set();
        }
        protected void socket_closed_by_remote_side(easy_socket.tcp.Socket_Data sender, EventArgs e)
        {
            int res = System.Threading.WaitHandle.WaitAny(this.HexaViewWaitHandles);

            if (res == 0) // close event
            {
                return;
            }
            if (sender == this.socket_to_srv)
            {
                this.evtConnectedToServer.Reset();
            }
            this.add_info("Connection closed by " + sender.RemoteIP + ":" + sender.RemotePort);
            this.check_close(sender);
            this.refresh_data();
            this.evtNotWrittingData.Set();
        }
        public long proxy_time_out = 20;// timeout in sec

        #endregion

        #region constructors

        public ClassProxy()
        {
            this.hevt_connected                 = new System.Threading.AutoResetEvent(false);
            this.hevt_data_arrival              = new System.Threading.AutoResetEvent(false);
            this.hevt_remotely_closed           = new System.Threading.AutoResetEvent(false);
            this.hevt_error                     = new System.Threading.AutoResetEvent(false);
            this.hevt_connection_state_unlocked = new System.Threading.AutoResetEvent(true);

            this.connection_state = PROXY_CONNECTION_STATE.CLOSED;
            this.socket           = new easy_socket.tcp.Socket_Data();
            this.socket.event_Socket_Data_Error       += new easy_socket.tcp.Socket_Data_Error_EventHandler(socket_event_Socket_Data_Error);
            this.socket.event_Socket_Data_DataArrival += new easy_socket.tcp.Socket_Data_DataArrival_EventHandler(socket_event_Socket_Data_DataArrival);
            this.socket.event_Socket_Data_Connected_To_Remote_Host += new easy_socket.tcp.Socket_Data_Connected_To_Remote_Host_EventHandler(socket_event_Socket_Data_Connected_To_Remote_Host);
            this.socket.event_Socket_Data_Closed_by_Remote_Side    += new easy_socket.tcp.Socket_Data_Closed_by_Remote_Side_EventHandler(socket_event_Socket_Data_Closed_by_Remote_Side);
            this.socket.event_Socket_Data_Send_Completed           += new easy_socket.tcp.Socket_Data_Send_Completed_EventHandler(socket_event_Socket_Data_Send_Completed);
            this.socket.event_Socket_Data_Send_Progress            += new easy_socket.tcp.Socket_Data_Send_Progress_EventHandler(socket_event_Socket_Data_Send_Progress);
        }
Esempio n. 17
0
 protected void socket_connected_to_remote_host(easy_socket.tcp.Socket_Data sender, EventArgs e)
 {
     if (clt.LocalIPEndPoint != null)
     {
         this.Text  = "Connected to " + myip + ":" + myport.ToString();
         this.Text += " local port:" + clt.LocalIPEndPoint.Port.ToString();
     }
     if (this.textBox_telnet.Text != "")
     {
         // return to a new line (split != send and send/receive)
         if (!this.textBox_telnet.Text.EndsWith("\r\n"))
         {
             this.textBox_telnet_add("\r\n");
         }
     }
     this.textBox_telnet_add("Connected to remote host.\r\n");
     if (this.b_telnet_protocol)
     {
         this.telnet.reset();
     }
 }
        public void new_tcp_interactive(System.Net.Sockets.Socket s, string remote_srv_ip, int remote_srv_port)
        {
            this.evtNotWrittingData   = new System.Threading.AutoResetEvent(true);
            this.evtStop              = new System.Threading.ManualResetEvent(false);
            this.evtConnectedToServer = new System.Threading.ManualResetEvent(false);
            this.HexaViewWaitHandles  = new System.Threading.WaitHandle[] { this.evtStop, this.evtNotWrittingData };

            System.Net.IPEndPoint ipep = (System.Net.IPEndPoint)s.RemoteEndPoint;
            this.Text          = "Transfer between client " + ipep.Address.ToString() + ":" + ipep.Port + " and server " + remote_srv_ip + ":" + remote_srv_port.ToString();
            this.socket_to_clt = new easy_socket.tcp.Socket_Data(s);
            this.socket_to_clt.event_Socket_Data_Closed_by_Remote_Side += new easy_socket.tcp.Socket_Data_Closed_by_Remote_Side_EventHandler(socket_closed_by_remote_side);
            this.socket_to_clt.event_Socket_Data_DataArrival           += new easy_socket.tcp.Socket_Data_DataArrival_EventHandler(socket_data_arrival);
            this.socket_to_clt.event_Socket_Data_Error += new easy_socket.tcp.Socket_Data_Error_EventHandler(socket_error);

            this.socket_to_srv = new easy_socket.tcp.Socket_Data();
            this.socket_to_srv.event_Socket_Data_Closed_by_Remote_Side    += new easy_socket.tcp.Socket_Data_Closed_by_Remote_Side_EventHandler(socket_closed_by_remote_side);
            this.socket_to_srv.event_Socket_Data_Connected_To_Remote_Host += new easy_socket.tcp.Socket_Data_Connected_To_Remote_Host_EventHandler(socket_connected_to_remote_host);
            this.socket_to_srv.event_Socket_Data_DataArrival += new easy_socket.tcp.Socket_Data_DataArrival_EventHandler(socket_data_arrival);
            this.socket_to_srv.event_Socket_Data_Error       += new easy_socket.tcp.Socket_Data_Error_EventHandler(socket_error);
            this.socket_to_srv.connect(remote_srv_ip, remote_srv_port);
        }
        protected void socket_closed_by_remote_side(easy_socket.tcp.Socket_Data sender, EventArgs e)
        {
            this.textBox_telnet_add("Connection closed by remote side.\r\n");

            // check if we are redirected to another whois server
            string str_last_whois_server_reply;
            // keep only last server reply (remember we have written "Used server:\t" before data arrival)
            int pos = this.textBox_telnet.Text.LastIndexOf("Used server:\t");

            if (pos < 0)
            {
                this.panel_control.Enabled = true;
                return;
            }
            // extract last server reply only from textbox
            str_last_whois_server_reply = this.textBox_telnet.Text.Substring(pos);
            // search "Whois server" in server reply
            string[] res   = null;
            bool     b_res = Tools.Text.ClassEreg.ereg(@"(whois server)([^w]*)(whois.)([^ \t\r\n]*)", str_last_whois_server_reply, ref res);

            // if not found we should have informations
            if (!b_res)
            {
                this.panel_control.Enabled = true;
                return;
            }
            // if whois server is the same as the current one
            if (this.whois_server == "whois." + res[4])
            {
                this.panel_control.Enabled = true;
                return;
            }
            this.whois_server = "whois." + res[4];
            this.textBox_telnet_add("Used server:\t" + this.whois_server + "\r\n");
            this.socket.close();
            this.socket.connect(this.whois_server, 43);
        }
 protected void socket_error(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_Exception e)
 {
     this.textBox_telnet_add("Socket Error: " + e.exception.Message + "\r\n");
     this.panel_control.Enabled = true;
 }
        protected void socket_data_arrival(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_ReceiveDataSocket e)
        {
            string strdata = System.Text.Encoding.Default.GetString(e.buffer, 0, e.buffer_size);

            this.textBox_telnet_add(strdata + "\r\n");
        }
 protected void socket_connected_to_remote_host(easy_socket.tcp.Socket_Data sender, EventArgs e)
 {
     this.textBox_telnet_add("Connected to remote host.\r\n");
     // host ip
     this.socket.send(this.data_to_send + "\r\n");
 }
        protected void socket_data_arrival(easy_socket.tcp.Socket_Data sender, easy_socket.tcp.EventArgs_ReceiveDataSocket e)
        {
            int res;

            System.Threading.WaitHandle[] mHexaViewWaitHandles = new System.Threading.WaitHandle[] { this.evtStop, this.evtConnectedToServer };

            // if sender is client
            if (sender == this.socket_to_clt)
            {
                // wait to be connected to server before trying to translate data
                res = System.Threading.WaitHandle.WaitAny(mHexaViewWaitHandles);
                if (res == 0) // close event
                {
                    return;
                }
            }

            res = System.Threading.WaitHandle.WaitAny(this.HexaViewWaitHandles);
            if (res == 0) // close event
            {
                return;
            }

            System.Drawing.Color color = System.Drawing.Color.Black;
            bool b_transmit            = false;

            if (sender == this.socket_to_clt)
            {
                // transfer data if required
                if (this.radioButton_clt_to_srv_allow.Checked)
                {
                    b_transmit = true;
                }
                else if (this.radioButton_clt_to_srv_block.Checked)
                {
                    b_transmit = false;
                }
                else// query
                {
                    string msg = "Do you want to allow the transfer of following data from " + sender.RemoteIP + ":" + sender.RemotePort.ToString() + "?\r\n"
                                 + "Hexa Data:\r\n"
                                 + this.split_in_multiple_lines(easy_socket.hexa_convert.byte_to_hexa(e.buffer), 50)
                                 + "Text Data:\r\n"
                                 + this.split_in_multiple_lines(System.Text.Encoding.Default.GetString(e.buffer), 50);

                    b_transmit = (MessageBox.Show(this, msg, "Tcp Interactive", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
                }
                if (b_transmit)
                {
                    this.socket_to_srv.send(e.buffer);
                    color = System.Drawing.Color.Blue;
                }
                else
                {
                    color = System.Drawing.Color.Violet;
                }
            }
            else
            {
                // transfer data if required
                if (this.radioButton_srv_to_clt_allow.Checked)
                {
                    b_transmit = true;
                }
                else if (this.radioButton_srv_to_clt_block.Checked)
                {
                    b_transmit = false;
                }
                else// query
                {
                    string msg = "Do you want to allow the transfer of following data from " + sender.RemoteIP + ":" + sender.RemotePort.ToString() + "?\r\n"
                                 + "Hexa Data:\r\n"
                                 + this.split_in_multiple_lines(easy_socket.hexa_convert.byte_to_hexa(e.buffer), 50)
                                 + "Text Data:\r\n"
                                 + this.split_in_multiple_lines(System.Text.Encoding.Default.GetString(e.buffer), 50);
                    b_transmit = (MessageBox.Show(this, msg, "Tcp Interactive", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
                }
                if (b_transmit)
                {
                    this.socket_to_clt.send(e.buffer);
                    color = System.Drawing.Color.Black;
                }
                else
                {
                    color = System.Drawing.Color.Red;
                }
            }
            if (b_transmit)
            {
                this.add_info("Data from " + sender.RemoteIP + ":" + sender.RemotePort.ToString());
            }
            else
            {
                this.add_info("Data from " + sender.RemoteIP + ":" + sender.RemotePort.ToString() + "(Blocked)");
            }
            // color depends of sender && user action
            this.add_data(e.buffer, color);
            this.refresh_data();
            this.evtNotWrittingData.Set();
        }