/// <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 += new EventHandler(VncClientConnectionLost); vnc.ServerCutText += new EventHandler(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. if ((_Password == null) || (_Password.Length == 0)) { _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(); } }
static void GetFrame(string ip_address, string password, string output_dir) { GotFrame = false; try { VncClient vnc = new VncClient(); vnc.Connect(ip_address); vnc.Authenticate(password); vnc.Initialize(); vnc.StartUpdates(); Framebuffer = new Bitmap(vnc.Framebuffer.Width, vnc.Framebuffer.Height, PixelFormat.Format32bppPArgb); vnc.VncUpdate += new VncUpdateHandler(vnc_VncUpdate); DateTime FrameGrabTimeout = DateTime.Now.AddSeconds(30); while (!GotFrame) { if (DateTime.Now > FrameGrabTimeout) break; Thread.Sleep(500); } vnc.Disconnect(); if (output_dir.Length == 0) output_dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); DirectoryInfo dir = new DirectoryInfo(output_dir); dir.Create(); Framebuffer.Save(dir.FullName + "\\" + ip_address + ".png", ImageFormat.Png); } catch (ObjectDisposedException s) { Console.Write("ERROR authenticating to " + ip_address + ".\n\r"); return; } catch (Exception e) { Console.Write("ERROR contacting " + ip_address + ". " + e.Message + "\n\r"); return; } Console.Write("Captured " + ip_address + "\n\r"); }
/// <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(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 = viewOnly; 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. var password = GetPassword(); if (password != null) { Authenticate(password); } } else { // No password needed, so go ahead and Initialize here Initialize(); } }
/// <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(); } }
/// <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) { 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.IsShared = IsShared; vnc.ConnectionLost += new VncClient.ConnectionLostHandler(VncClientConnectionLost); vnc.ServerCutText += new EventHandler(VncServerCutText); vnc.ConnectionOpen += new VncClient.ConnectionOpenedHandler(vnc_ConnectionOpen); vnc.Connect(host, display, VncPort, viewOnly); SetScalingMode(scaled); }