Just Enough Developed Infrastructure

Sending Vnc Keystrokes Using Java

I have been experimenting with sending VNC keystrokes in different ways before . To finalize these experiments I decided to create a java library that is able to send keys towards a vnc server. I take advantage of existing logic of the vnc-tight project.

The project provides the source for a java based vncviewer, but the problem is that it uses an applet awt-based interface. I wanted it to be used from the commandline without the X requirement.

Presenting the new project jvncsender

The commandline version <% codify(:shell) do %> usage: java -jar jvncsender.jar [-list] [-help] -host -port -text [-password ] [-wait ] -help print this message -host hostname or ip-address to send it to -list list keymappings -password password to use -port port to connect to f.i. 5900 -text text to send, (can be use multiple times) -wait seconds to wait in between sending different texts (default=1s)

text can also take special keys f.i. like "linux ks=ks.cfg" use -list options to see all keymappings <% end %>

or from within java: <% codify(:java) do %> try { VncSender vncSender=new VncSender(vncHost,vncPort,vncPassword); vncSender.setVncWaitTime(timeInSec);

} catch (Exception ex) { System.out.println(ex.toString()); } <% end %>

I've been using it for automating kickstarts via VNC vmware.

F.i. my text string for kickstarting an ubuntu server without creating a custom cdrom would look like this:

<% codify(:java) do %> vncText=new String[]{ "", "/install/vmlinuz noapic" + " hostname=pxeboot domain=jedi2.be netcfg/get_domain=jedi.be interface=eth0 netcfg/get_ipaddress= netcfg/get_netmask= netcfg/get_gateway= " , " netcfg/get_nameservers= netcfg/disable_dhcp=true" , " netcfg/choose_interface=eth0 netcfg/wireless_wep= preseed/url= debian-installer=en_US auto locale=en_US kbd-chooser/method=us", " fb=false debconf/frontend=noninteractive", " console-setup/ask_detect=false console-setup/modelcode=pc105 console-setup/layoutcode=us ", " initrd=/install/initrd.gz -- " }; <% end %>

Note: this only works if your keyboard mapping is in us mode, as the keymappings are scancodes not actual ascii codes.

<% codify(:shell) do %>

to get all vnc code

$ svn co https://vnc-tight.svn.sourceforge.net/svnroot/vnc-tight vnc-tight

to get all vnc java code

$ svn co https://vnc-tight.svn.sourceforge.net/svnroot/vnc-tight/trunk/java vnc-tight-java <% end %>

I ended up using the jar file announced TightVNC: VNC Viewer with SSH Tunneling - April 2010

In order to get access to certain functions, I put my classes inside the same package. But because the jar file was signed, I needed to remove the signing:

<% codify(:shell) do %> $ wget http://www.tightvnc.com/download/tightvnc-1.5.1-jviewer-bin.zip $ unzip tightvnc-1.5.1-jviewer-bin.zip $ cd tightvnc-1.5.1-jviewer-bin $ ls *.jar TightVncViewer.jar $ mkdir newjar $ cd newjar $ jar -xvf ../TightVncViewer.jar $ rm -rf META-INF $ jar -cvf TighTVncViewer-unsigned.jar <% end %>