예제 #1
0
        public void ConnectTcpArgumentsTest()
        {
            VncClient client = new VncClient();

            Assert.Throws <ArgumentNullException>(() => client.Connect(null, 5900, null));
            Assert.Throws <ArgumentOutOfRangeException>(() => client.Connect("localhost", -1, null));
        }
예제 #2
0
파일: CrackVNC.cs 프로젝트: sdsecurity/SDXC
        public override Server creack(String ip, int port, String username, String password, int timeOut)
        {
            VncClient vc     = null;
            Server    server = new Server();

            try
            {
                vc = new VncClient();

                Boolean result = vc.Connect(ip, 0, port);
                if (result)
                {
                    server.isSuccess = vc.Authenticate(password);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally {
                if (vc != null)
                {
                    vc.Disconnect();
                }
            }
            return(server);
        }
예제 #3
0
 private void TestConfig(MainWindowViewModel vm)
 {
     using (var client = new VncClient(config.BitsPerPixel, config.Depth))
     {
         try
         {
             client.Connect(vm.Host, vm.Port);
             client.Authenticate(new VncAuthenticator(vm.Password));
             client.Disconnect();
             MessageBox.Show("OK.", "Config", MessageBoxButton.OK, MessageBoxImage.Information);
         }
         catch (SocketException e)
         {
             MessageBox.Show(e.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
         }
         catch (VncSecurityException e)
         {
             MessageBox.Show(e.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
         }
         catch (Exception e)
         {
             MessageBox.Show($"{e.Message}\r\n{e.StackTrace}", Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
예제 #4
0
        public void Test()
        {
            using (var vncClient = new VncClient())
            {
                vncClient.Connect(Address, 5900,
                                  new VncClientConnectOptions {
                    OnDemandMode = true, PasswordRequiredCallback = c => "100".ToArray()
                });

                var width  = 200;
                var height = 300;
                var copy   = vncClient.GetFramebuffer(100, 100, width, height);
                var bitmap = this.CreateBitmap(copy, width, height);
                bitmap.Save(@"C:\TestOutput\Test.bmp", ImageFormat.Bmp);
                Assert.AreNotEqual(Color.Black.ToArgb(), bitmap.GetPixel(10, 10).ToArgb());
            }
        }
예제 #5
0
        /// <summary>
        /// Connect to a VNC Host and determine whether or not the server requires a password.
        /// </summary>
        /// <param name="host">The IP Address or Host Name of the VNC Host.</param>
        /// <param name="display">The Display number (used on Unix hosts).</param>
        /// <param name="viewOnly">Determines whether mouse and keyboard events will be sent to the host.</param>
        /// <param name="scaled">Determines whether to use desktop scaling or leave it normal and clip.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if host is null.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if display is negative.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already Connected.  See <see cref="VncSharp.RemoteDesktop.IsConnected" />.</exception>
        public void Connect(string host, int display, bool viewOnly, bool scaled)
        {
            // TODO: Should this be done asynchronously so as not to block the UI?  Since an event
            // indicates the end of the connection, maybe that would be a better design.
            InsureConnection(false);

            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (display < 0)
            {
                throw new ArgumentOutOfRangeException("display", display, "Display number must be a positive integer.");
            }

            // Start protocol-level handling and determine whether a password is needed
            vnc = new VncClient();
            vnc.ConnectionLost += VncClientConnectionLost;
            vnc.ServerCutText  += VncServerCutText;

            passwordPending = vnc.Connect(host, display, VncPort, viewOnly);

            SetScalingMode(scaled);

            if (passwordPending)
            {
                // Server needs a password, so call which ever method is refered to by the GetPassword delegate.
                string password = GetPassword();

                if (password == null)
                {
                    // No password could be obtained (e.g., user clicked Cancel), so stop connecting
                    return;
                }
                else
                {
                    Authenticate(password);
                }
            }
            else
            {
                // No password needed, so go ahead and Initialize here
                Initialize();
            }
        }
예제 #6
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var config = await ReadConfigAsync();

            _VncClient = new VncClient(config.BitsPerPixel, config.Depth);
            _VncClient.Connect(config.Host, config.Port);

            var auth = new VncAuthenticator(config.Password);

            _VncClient.Authenticate(auth);
            _VncClient.Initialize();

            _VncImage       = new WriteableBitmap(_VncClient.Framebuffer.Width, _VncClient.Framebuffer.Height);
            VncImage.Source = _VncImage;

            _VncClient.OnFramebufferUpdate += _VncClient_OnFramebufferUpdate;
            _VncClient.ReceiveUpdates();
        }
예제 #7
0
        /// <summary>
        /// Connect to a VNC Host and determine whether or not the server requires a password.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">Thrown if host is null.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if display is negative.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already Connected.
        /// See <see cref="IsConnected" />.</exception>
        public void Connect()
        {
            // TODO: Should this be done asynchronously so as not to block the UI?  Since an event
            // indicates the end of the connection, maybe that would be a better design.
            InsureConnection(false);

            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (display < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(display), display,
                                                      "Display number must be a positive integer.");
            }

            // Start protocol-level handling and determine whether a password is needed
            vnc = new VncClient();
            vnc.ConnectionLost += VncClientConnectionLost;
            vnc.ServerCutText  += VncServerCutText;
            vnc.ViewOnly        = viewOnlyMode;

            passwordPending = vnc.Connect(host, display, VncPort, viewOnlyMode);

//            SetScalingMode(scaled);

            if (passwordPending)
            {
                if (password != null)
                {
                    Authenticate(password);
                }
            }
            else
            {
                // No password needed, so go ahead and Initialize here
                Initialize();
            }
        }
예제 #8
0
        public void ConnectStreamArgumentsTest()
        {
            VncClient client = new VncClient();

            Assert.Throws <ArgumentNullException>(() => client.Connect(null, null));
        }