h1

When you can’t access get to the PC, have it come find you

October 7th, 2002

One of the many many things I really like about VNC is that you can start up a listener and then have someone throw a remote control session to your address. This came in handy for me at a client last year.

The client’s VPN software wouldn’t work through my home cable router at that time (since fixed with a flash ROM upgrade). I couldn’t use PC Anywhere or VNC in their usual ways because the machine was various levels deep into the network and it would be impossible to expose its ports to the Internet at large.

What I ended up doing was writing a Perl program to run on the PC in question that would once a minute check a file on my webserver called vnclisten.on. If that file exists, it reads from it one text line containing the IP address I want it to throw a connection to, and tells VNC to connect there.

Once that’s running, to control that machine, I make sure my port 5500 is exposed on the internet wherever I am, and then I drop a file called vnclisten.on onto my webserver in the right spot, containing my current IP address. Within a minute, I have a remote control session pop up! At that point, I have one minute to go kill or rename the vnclisten.on file so I don’t get multiple sessions popping up.

It doesn’t matter how deep into the network the serving machine is, as long as it has net access and your listening machine can expose its port 5500 on an external address either directly or via port forwarding.

Here is the Perl program:


#
# listencheck.pl
#
# checks url every minute to find address of
# listening vnc client and throws a vnc session
# to that address if so

# syntax: listencheck url interval


my $url = shift || 'http://www.myserver.xxx/vnclisten.on';
my $interval = shift || 60;
my $logfile = "listencheck.log";
my $vnc = ""c:\program files\orl\vnc\winvnc"";


use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("ListenCheck/2.0");


while (1) {
 my $req = HTTP::Request->new(GET => $url);
  my $res = $ua->request($req);
  if ($res->is_success) {
  my ($addr) = $res->content =~ /\s*(.*)\s*/;
  system("$vnc -connect $addr");
  open LOG, ">>$logfile";
  print LOG localtime(time) . " connect to $addr \n";
  close LOG;
 }
 sleep $interval;
}

Set your screensaver to "blank screen", set a short delay, and make it ask for a password!

Comments are closed.