Apr 9 2003

Beacon watcher

If you ever want to watch the beacons being sent by your TiVo Unit or the TiVo Media Server on your PC, you can use the following piece of perl code. This script will listen for UDP messages on port 2190 and will print them as they arrive. If you try to run this on the same PC where you have the TiVo Desktop installed, you will get an error message, because we can’t bind to port 2190 – it has been allocated by the TiVo Beacon service. You can “stop” the service via net stop TivoBeacon, run the script and later on restart the service via net start TivoBeacon.

Here’s what the script will print when both the TiVo unit and the Desktop Server are active:

[Wed Apr  9 18:46:16 2003] santafe:2035 sent beacon packet
[Wed Apr  9 18:46:16 2003]      TiVoConnect=1
[Wed Apr  9 18:46:16 2003]      Machine=SANTAFE
[Wed Apr  9 18:46:16 2003]      Identity={239F9D3F-31E0-410E-8991-19DF88661779}
[Wed Apr  9 18:46:16 2003]      Method=Broadcast
[Wed Apr  9 18:46:16 2003]      Platform=pc/WinNT:5.1.2600
[Wed Apr  9 18:46:16 2003]      Services=TiVoMediaServer:8080/http
[Wed Apr  9 18:47:08 2003] 172.25.36.113:2190 sent beacon packet
[Wed Apr  9 18:47:08 2003]      tivoconnect=1
[Wed Apr  9 18:47:08 2003]      swversion=4.0-01-2-140
[Wed Apr  9 18:47:08 2003]      method=broadcast
[Wed Apr  9 18:47:08 2003]      identity=140000080205DD9
[Wed Apr  9 18:47:08 2003]      machine=Living Room
[Wed Apr  9 18:47:08 2003]      platform=tcd/Series2
[Wed Apr  9 18:47:08 2003]      services=TiVo-ServeTcdVideo-1:2191/tvbus_v3

And here is the code for the script:

#!c:\perl\bin\perl.exe
use strict;
use IO::Socket;
use constant BEACON_PORT => 2190;
use constant MAXLEN      => 1024;
my $socket=IO::Socket::INET->new(LocalPort=>BEACON_PORT,Proto => 'udp')
  or die "unable to create socket - $!";
while ($socket->recv(my $msg,MAXLEN)) {
    my($port, $ipaddr) = sockaddr_in($socket->peername);
    my $sender=gethostbyaddr($ipaddr, AF_INET);
    $sender=inet_ntoa($ipaddr) unless(defined($sender));
    print "[".scalar(localtime())."] $sender:$port sent beacon packet\n";
    foreach (split(/[\n\r]/,$msg)) {
        s/^/\t/;
        print "[".scalar(localtime())."] $_\n";
    }
}

Leave a Reply