VNC Robot
October 8th, 2009
Today at work I had a interesting request. Make a screenshot of a Flash application and send this the customer by mail every 5 minutes or so. First I though that it would be best to utilize some Actionscript with PHP/GD. This was ok but the other guys seemed to prefer some other hack. So I came up with using something like Browsershots, or some CutyCapt/IECapt, Python, Django combination. This seemed too complicated though.
So I finally settled with using VNC Robot. This thing is actually really funny, its like (shudder) Windows Scripting Host in VNC. Perfect!.
Originally I also looked into Ruby/Mechanize and other alike but with Flash thats a problem these days...
Here is a sample script I created and other nifty examples can be found here.
# Open Firefox from start menu
Mouse move to=x:145,y:755 wait=1000
Mouse click count=1
# Go to location bar
Mouse move to=x:262,y:65 wait=1000
Mouse click count=1
# Go to webpage
# Press Ctrl+l wait=1000
Press Backspace count=20
Type "http://10.0.0.9" wait=1000
Press Enter wait=6000
# Go to login form
Press Tab wait=1000
Type "usernamewashere" wait=1000
Press Tab wait=1000
Type "passwordwashere" wait=1000
# Skip over the "Do you want to remember password question"
Press Enter wait=1000
Press Enter wait=1000
Wait 10000
# Take a screenshot and send it to John
Screenshot /tmp/stock.jpg
Sendmail subject="XYZ Application stock on {_DATE}" from="root@yourmachine" to="foobar@blahblubb.org"
server="localhost" attach="/tmp/stock.jpg"
# Close the browser so that we can rerun the script safely
Press Alt+F4 wait=500
Press Alt+F4 wait=500
The result looks like this (scaled down).
Remote VNC Connections - Make it easy for users
February 25th, 2009
Do you often need to help friends or family with their Windows system? Something broken on their system and talking them through is just totally impossible? Well probably you like this then. Let them install VNC, e.g. RealVNC. There is a free edition, so make sure they don't install something else.
After that the only thing they need to do is right click on that VNC logo in the Statusbar and select Add remote client. That option is really neat. It lets the user open a reverse connection to an given IP/Port combination, so all that trouble with their firewall or router doesn't matter anymore.
Of course to make things work you need to give them a valid URL or IP combination so that they can connect to. e.g. mydomain.com:5500.
I myself sit behind a NAT'd and routed connection which makes direct connections no good. So I often just SSH tunnel myself to a remote machine for this purpose. The magic to make this happen is that you open two consoles, one for your vnc and another one for your tunnel.
The commands you will need are
- vncviewer -listen
- ssh -Nv -R 0.0.0.0:5500:localhost:5500 user@mydomain.com
Voila! Your user can connect to your connection allowing you to solve their problems more quickly, saving you alot of nerve.
If you are like me and you still like to save more keystrokes, maybe this screen config will come in handy.
% cat bin/screenvncsessionconfig screen -t "ssh" 1 ssh -Nv -R 0.0.0.0:5500:localhost:5500 user@mydomain.com screen -t "vncviewer" 2 vncviewer -listen
For your e.g. Zsh config use this:
% which remotevnc remotevnc: aliased to ssh-add; screen -S vnc -c /home/br/bin/screenvncsessionconfig
Good Luck !