예제 #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (vncControl.Client.IsConnected)
            {
                vncControl.Client.Close();
            }
            else
            {
                var hostname = txtHostname.Text.Trim();
                if (hostname == "")
                {
                    MessageBox.Show(this, "Hostname isn't set.", "Hostname",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int port;
                if (!int.TryParse(txtPort.Text, out port) || port < 1 || port > 65535)
                {
                    MessageBox.Show(this, "Port must be between 1 and 65535.", "Port",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var options = new Vnc.VncClientConnectOptions();
                if (txtPassword.Text != "")
                {
                    options.Password = txtPassword.Text.ToCharArray();
                }

                try {
                    try {
                        Cursor = Cursors.WaitCursor;
                        var client = new TcpClient();
                        try {
                            client.Connect(hostname, port);
                            vncControl.Client.Connect(client.GetStream(), options);
                        }
                        finally {
                            Cursor = Cursors.Default;
                        }
                    }
                    catch (Vnc.VncException ex) {
                        MessageBox.Show(this,
                                        "Connection failed (" + ex.Reason.ToString() + ").",
                                        "Connect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    catch (SocketException ex) {
                        MessageBox.Show(this,
                                        "Connection failed (" + ex.Error.ToString() + ").",
                                        "Connect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    catch (Exception ex) {
                        MessageBox.Show(this,
                                        "Connection failed (" + ex.ToString() + ").",
                                        "Connect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    vncControl.Focus();
                }
                finally {
                    if (options.Password != null)
                    {
                        Array.Clear(options.Password, 0, options.Password.Length);
                    }
                }
            }
        }
예제 #2
0
        private void OnClick(object sender, EventArgs e)
        {
            if (this.vncControl.Client.IsConnected)
            {
                this.vncControl.Client.Close();
            }
            else
            {
                //var hostname = this.txtHostname.Text.Trim();
                var hostname = "";
                //if (hostname == string.Empty)
                //{
                //    MessageBox.Show(
                //        this,
                //        "Hostname isn't set.",
                //        "Hostname",
                //        MessageBoxButtons.OK,
                //        MessageBoxIcon.Error);
                //    return;
                //}

                //int port;
                //if (!int.TryParse(this.txtPort.Text, out port) || port < 1 || port > 65535)
                int port = 5900;
                if (port < 1 || port > 65535)
                {
                    MessageBox.Show(
                        this,
                        "Port must be between 1 and 65535.",
                        "Port",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }

                var options = new Vnc.VncClientConnectOptions();
                if (this.txtPassword.Text != string.Empty)
                {
                    //php에서 로그인하기위해서 사용하는 코드

                    StringBuilder postParams = new StringBuilder();
                    //postParams.Append("id=" + textID.Text);
                    //postParams.Append("&pw=" + textPW.Text);

                    Encoding encoding = Encoding.UTF8;
                    byte[]   result   = encoding.GetBytes(postParams.ToString());


                    // 타겟이 되는 웹페이지 URL
                    string         Url       = "http://3men.pe.kr/InCodeOutIp.php?code=" + this.txtPassword.Text;
                    HttpWebRequest wReqFirst = (HttpWebRequest)WebRequest.Create(Url);

                    // HttpWebRequest 오브젝트 설정
                    wReqFirst.Method        = "POST";
                    wReqFirst.ContentType   = "application/x-www-form-urlencoded";
                    wReqFirst.ContentLength = result.Length;

                    Stream postDataStream = wReqFirst.GetRequestStream();
                    postDataStream.Write(result, 0, result.Length);
                    postDataStream.Close();

                    HttpWebResponse wRespFirst = (HttpWebResponse)wReqFirst.GetResponse();

                    // Response의 결과를 스트림을 생성합니다.
                    Stream       respPostStream = wRespFirst.GetResponseStream();
                    StreamReader readerPost     = new StreamReader(respPostStream, Encoding.Default);

                    // 생성한 스트림으로부터 string으로 변환합니다.
                    string resultPost = readerPost.ReadToEnd();
                    int    resul_leng = resultPost.Length;
                    //MessageBox.Show(resultPost);
                    //
                    if (resultPost.Length >= 20)
                    {
                        string[] spl_result  = resultPost.Split(new char[] { ':' });
                        string[] spl_result2 = spl_result[2].Split(new char[] { '"' });
                        // MessageBox.Show(spl_result2[1].Trim());
                        hostname         = spl_result2[1].Trim();
                        options.Password = this.txtPassword.Text.ToCharArray();
                    }
                    else
                    {
                        MessageBox.Show("올바른 코드를 입력해주세요.");
                        return;
                    }
                }

                try
                {
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;
                        try
                        {
                            this.vncControl.Client.Connect(hostname, port, options);
                        }
                        finally
                        {
                            this.Cursor = Cursors.Default;
                        }
                    }
                    catch (Vnc.VncException ex)
                    {
                        MessageBox.Show(
                            this,
                            "Connection failed (" + ex.Reason.ToString() + ").",
                            "Connect",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        return;
                    }
                    catch (SocketException ex)
                    {
                        MessageBox.Show(
                            this,
                            "Connection failed (" + ex.SocketErrorCode.ToString() + ").",
                            "Connect",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        return;
                    }

                    this.vncControl.Focus();
                }
                finally
                {
                    if (options.Password != null)
                    {
                        Array.Clear(options.Password, 0, options.Password.Length);
                    }
                }
            }
        }
예제 #3
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (vncControl.Client.IsConnected)
            {
                vncControl.Client.Close();
            }
            else
            {
                var hostname = txtHostname.Text.Trim();
                if (hostname == "")
                {
                    MessageBox.Show(this, "Hostname isn't set.", "Hostname",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int port;
                if (!int.TryParse(txtPort.Text, out port) || port < 1 || port > 65535)
                {
                    MessageBox.Show(this, "Port must be between 1 and 65535.", "Port",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var options = new Vnc.VncClientConnectOptions();
                if (txtPassword.Text != "") { options.Password = txtPassword.Text.ToCharArray(); }

                try
                {
                    try
                    {
                        Cursor = Cursors.WaitCursor;
                        try { vncControl.Client.Connect(hostname, port, options); }
                        finally { Cursor = Cursors.Default; }
                    }
                    catch (Vnc.VncException ex)
                    {
                        MessageBox.Show(this,
                                        "Connection failed (" + ex.Reason.ToString() + ").",
                                        "Connect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    catch (SocketException ex)
                    {
                        MessageBox.Show(this,
                                        "Connection failed (" + ex.SocketErrorCode.ToString() + ").",
                                        "Connect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    vncControl.Focus();
                }
                finally
                {
                    if (options.Password != null)
                    {
                        Array.Clear(options.Password, 0, options.Password.Length);
                    }
                }
            }
        }