Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Listening on local port 5900.");
            Console.WriteLine("Try to connect! The password is: {0}", Password);

            // Wait for a connection.
            var listener = new TcpListener(IPAddress.Any, 5900);

            listener.Start();
            var client = listener.AcceptTcpClient();

            // Set up a framebuffer and options.
            var options = new VncServerSessionOptions {
                AuthenticationMethod = AuthenticationMethod.Password
            };

            // Create a session.
            Session                   = new VncServerSession();
            Session.Connected        += HandleConnected;
            Session.ConnectionFailed += HandleConnectionFailed;
            Session.Closed           += HandleClosed;
            Session.PasswordProvided += HandlePasswordProvided;
            Session.SetFramebufferSource(new VncScreenFramebufferSource("Hello World", Screen.PrimaryScreen));
            Session.Connect(client.GetStream(), options);

            // Let's go.
            Application.Run();
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Listening on local port 5900.");
            Console.WriteLine("Try to connect! The password is: {0}", password);

            // Wait for a connection.
            var listener = new TcpListener(IPAddress.Loopback, 5900);

            listener.Start();
            var client = listener.AcceptTcpClient();

            // Set up a framebuffer and options.
            var options = new VncServerSessionOptions();

            options.AuthenticationMethod = AuthenticationMethod.Password;

            // Create a session.
            session = new VncServerSession(
                new VncPasswordChallenge(),
                new ConsoleLogger());
            session.Connected        += HandleConnected;
            session.ConnectionFailed += HandleConnectionFailed;
            session.Closed           += HandleClosed;
            session.PasswordProvided += HandlePasswordProvided;
            session.SetFramebufferSource(new DummyFramebufferSource());
            session.Connect(client.GetStream(), options);

            // Let's go.
            Console.WriteLine("Hit ENTER to exit");
            Console.ReadLine();
        }
Beispiel #3
0
        public static int StartWithHeadlessVncPlatform <T>(
            this T builder,
            string host, int port,
            string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose)
            where T : AppBuilderBase <T>, new()
        {
            var tcpServer = new TcpListener(host == null ? IPAddress.Loopback : IPAddress.Parse(host), port);

            tcpServer.Start();
            return(builder
                   .UseHeadless(false)
                   .AfterSetup(_ =>
            {
                var lt = ((IClassicDesktopStyleApplicationLifetime)builder.Instance.ApplicationLifetime);
                lt.Startup += async delegate
                {
                    while (true)
                    {
                        var client = await tcpServer.AcceptTcpClientAsync();
                        var options = new VncServerSessionOptions
                        {
                            AuthenticationMethod = AuthenticationMethod.None
                        };
                        var session = new VncServerSession();

                        session.SetFramebufferSource(new HeadlessVncFramebufferSource(
                                                         session, lt.MainWindow));
                        session.Connect(client.GetStream(), options);
                    }
                };
            })
                   .StartWithClassicDesktopLifetime(args, shutdownMode));
        }
Beispiel #4
0
        public static void ListenerThread()
        {
            while (true)
            {
                // Wait for a connection.
                TcpClient client = listener.AcceptTcpClient();   //AcceptTcpClient 접속하는 클라이언트에 대해 TCPClient 객체 생성

                // Set up a framebuffer and options.
                var options = new VncServerSessionOptions();
                options.AuthenticationMethod = AuthenticationMethod.Password;

                // Virtual mouse
                var mouse = new VncMouse();

                // Virtual keyboard
                var keyboard = new VncKeyboard();

                // Create a session.
                session                   = new VncServerSession();
                session.LogData          += HandleLogData; //로그를 저장하기위해 새로추가
                session.Connected        += HandleConnected;
                session.ConnectionFailed += HandleConnectionFailed;
                session.Closed           += HandleClosed;
                session.PasswordProvided += HandlePasswordProvided;
                session.SetFramebufferSource(new VncScreenFramebufferSource("Hello World", Screen.PrimaryScreen));
                session.PointerChanged += mouse.OnMouseUpdate;
                session.KeyChanged     += keyboard.OnKeyboardUpdate;
                session.Connect(client.GetStream(), options);


                //세션을 저장하는곳

                NetWorkItem item;
                item.session   = session;
                item.tcpClient = client;
                sessionList.Add(item);

                // 접속한 ip따오는
                Socket     c        = client.Client;
                IPEndPoint ip_point = (IPEndPoint)c.RemoteEndPoint;  //누가요청했는지 접근할수있게 IPEndPoint속성을 이용
                clientIP = ip_point.Address.ToString();

                session.ip = ip_point.Address.ToString();

                // MessageBox.Show(ip);
                clientID   = session.UserData;
                session.id = clientID;
                // MessageBox.Show(userID);



                // Let's go.
                //Application.Run();
            }
        }
        private void ConnectService(TcpClient tcpClient)
        {
            try
            {
                string loalIp = GetLocalIpAddress();

                IPEndPoint remotePoint = tcpClient.Client.RemoteEndPoint as IPEndPoint;
                IPEndPoint localpPoint = tcpClient.Client.LocalEndPoint as IPEndPoint;

                OnAddLogEvent($"VNC连接接入,客户端ip:{remotePoint.Address},端口:{remotePoint.Port}");

                VncServerSessionOptions options = new VncServerSessionOptions();
                //设置需要密码验证
                options.AuthenticationMethod = AuthenticationMethod.Password;

                // 创建一个会话
                VncServerSession session = new VncServerSession();
                session.MaxUpdateRate     = 20;
                session.Connected        += HandleConnected;
                session.ConnectionFailed += HandleConnectionFailed;
                session.Closed           += HandleClosed;
                session.PasswordProvided += HandlePasswordProvided;
                session.CreatingDesktop  += Session_CreatingDesktop;

                //session.FramebufferCapturing += Session_FramebufferCapturing;
                session.FramebufferUpdating += Session_FramebufferUpdating;

                session.KeyChanged             += Session_KeyChanged;
                session.PointerChanged         += Session_PointerChanged;
                session.RemoteClipboardChanged += Session_RemoteClipboardChanged;

                //设置分享的屏幕等信息 连接名字 name
                string name = loalIp + ":" + localpPoint.Port + "--" + remotePoint.Address + ":" + remotePoint.Port;
                VncScreenFramebufferSource vncScreenSource = new VncScreenFramebufferSource(name, Screen.PrimaryScreen);
                session.SetFramebufferSource(vncScreenSource);

                Dictionary <string, string> connectInfo = new Dictionary <string, string>()
                {
                    { "LoalIp", loalIp },
                    { "LocalpPort", localpPoint.Port.ToString() },
                    { "RemoteIp", remotePoint.Address.ToString() },
                    { "RemotePort", remotePoint.Port.ToString() },
                };
                session.UserData = connectInfo;
                session.Connect(tcpClient, options);

                sessionList.Add(session);
            }
            catch (Exception ex)
            {
                OnAddLogEvent($"连接出现错误,原因:{ex.Message}");
            }
        }
Beispiel #6
0
        /// <summary>
        /// Listen to the given <see cref="HttpContext"/>
        /// </summary>
        /// <returns>
        /// A <see cref="Task"/> corresponding to the listen process.
        /// </returns>
        public async Task Listen()
        {
            var stream = new WebSocketStream(this.Socket);

            var options = new VncServerSessionOptions();

            options.AuthenticationMethod = AuthenticationMethod.Password;

            this.Vnc.Connect(stream, options);

            await this.closed.WaitAsync().ConfigureAwait(false);

            this.Socket.Dispose();
        }
Beispiel #7
0
        public static void Listen()
        {
            if (GV.IP.StartsWith("172.27"))
            {
                Random      Rand     = new Random();
                TcpListener listener = null;
                while (true)
                {
                    try
                    {
                        int iPort = Rand.Next(10000, 60000);//Max 65535
                        listener = new TcpListener(IPAddress.Any, iPort);
                        listener.Start();
                        ExecuteQuery("UPDATE c_machines set STATUS = 'Online', SystemState = '' ,RDPPort='" + iPort + "',CMVersion = '" + GV.sSoftwareVersion + "',LastSession='" + GV.sSessionID + "',LastUpdatedDate = GETDATE(), LastLoggedProjectID='" + GV.sProjectID + "' WHERE MachineID='" + GV.sMachineID + "';");
                        break;
                    }
                    catch (Exception ex)
                    {
                        listener = null;
                        Thread.Sleep(30000);
                    }
                }

                try
                {
                    var client = listener.AcceptTcpClient();

                    // Set up a framebuffer and options.
                    var options = new VncServerSessionOptions();
                    options.AuthenticationMethod = AuthenticationMethod.Password;

                    // Create a session.
                    Session                   = new VncServerSession();
                    Session.Connected        += SessionConnected;
                    Session.ConnectionFailed += ConnectionFailed;
                    Session.Closed           += ConnectionClosed;

                    Session.PasswordProvided += HandlePasswordProvided;
                    Session.SetFramebufferSource(new VncScreenFramebufferSource("Hello World", System.Windows.Forms.Screen.PrimaryScreen));
                    Session.Connect(client.GetStream(), options);
                }
                catch (Exception ex)
                {
                    ExecuteQuery("UPDATE c_machines set STATUS = 'Connection Error',RDPPort='',LastUpdatedDate = GETDATE() WHERE MachineID='" + GV.sMachineID + "';");
                    GM.Error_Log(System.Reflection.MethodBase.GetCurrentMethod(), ex, true, false);
                }
            }
        }
        public void NegotiateVersionBoth38Test(VncServerSessionOptions sessionOptions, AuthenticationMethod expectedAuthenticationMethod)
        {
            using (var stream = new TestStream())
            {
                // Mimick the client negotiating RFB 3.8
                VncStream clientStream = new VncStream(stream.Input);
                clientStream.SendString("RFB 003.008\n");
                stream.Input.Position = 0;

                VncServerSession session = new VncServerSession();
                session.Connect(stream, sessionOptions, startThread: false);

                Assert.True(session.NegotiateVersion(out AuthenticationMethod[] methods));

                Assert.Collection(
                    methods,
                    (m) => Assert.Equal(expectedAuthenticationMethod, m));

                stream.Output.Position = 0;

                Assert.Equal(Encoding.UTF8.GetBytes("RFB 003.008\n"), ((MemoryStream)stream.Output).ToArray());
            }
        }
Beispiel #9
0
        private void ConnectService(TcpClient tcpClient)
        {
            try
            {
                string loalIp = GetLocalIpAddress();

                IPEndPoint remotePoint = tcpClient.Client.RemoteEndPoint as IPEndPoint;
                Console.WriteLine($"VNC连接接入,客户端ip:{remotePoint.Address},端口:{remotePoint.Port}");

                VncServerSessionOptions options = new VncServerSessionOptions();
                //设置需要密码验证
                options.AuthenticationMethod = AuthenticationMethod.Password;

                // 创建一个会话
                VncServerSession session = new VncServerSession();

                session.Connected              += HandleConnected;
                session.ConnectionFailed       += HandleConnectionFailed;
                session.Closed                 += HandleClosed;
                session.PasswordProvided       += HandlePasswordProvided;
                session.CreatingDesktop        += Session_CreatingDesktop;
                session.KeyChanged             += Session_KeyChanged;
                session.PointerChanged         += Session_PointerChanged;
                session.RemoteClipboardChanged += Session_RemoteClipboardChanged;
                //设置分享的屏幕等信息 连接名字 name
                string name = loalIp + ":" + this.servicePort + "--" + remotePoint.Address + ":" + remotePoint.Port;
                VncScreenFramebufferSource vncScreenSource = new VncScreenFramebufferSource(name, Screen.PrimaryScreen);
                session.SetFramebufferSource(vncScreenSource);
                session.Connect(tcpClient, options);

                sessionList.Add(session);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"连接出现错误,原因:{ex.Message}");
            }
        }