# Help with Telnet script for mini



## HuskerMike (Jun 16, 2014)

I've been working on keeping my minis from sleeping using a telnet script, but I don't understand enough to do it properly.
Here's my script so far:

192.168.1.10 31339
SEND "IRCODE CLEAR"

But I can't find anything about how to maybe delay before the "send" command (or if that's even necessary), or how to close when done, etc.

Every thread on this topic assumes telnet knowledge, so if anyone can comment, or even post a script example, that would be awesome. :up:


----------



## telemark (Nov 12, 2013)

What computers / OS's do you have available at home?


----------



## HuskerMike (Jun 16, 2014)

I'm using a windows PC. I'm just looking to finish the telnet script in notepad, run with Telnet Scripting Tool 1.0. There have been probably several hundred posts about this process here, but none of them contain the actual script. It's almost comical how ALL the threads narrowly avoid it - going off-topic or dying before getting helpful.


----------



## HuskerMike (Jun 16, 2014)

Ok, I've discovered one mistake - I've been forgetting the \m at the end of the "SEND" lines.

So, it kind-of works, but I can't seem to do what I want fully. In the new script below, I'm trying to set several minis to different channels using the same script. Not sure if I can put another IP address into the same script. Feel free to jump in with any tips.

192.168.1.10 31339 (note - setting main Tivo to channel 1352)
SEND "IRCODE LIVETV\m"
SEND "SETCH 1352\m"

192.168.1.14 31339 (note - trying to set Mini #1 to channel 1500, doesn't work).
SEND "IRCODE LIVETV\m"
SEND "SETCH 1500\m"

(Need to close the dialog boxes somehow here)

Also the SETCH command no longer seems to work on my mini boxes, so I'll have to figure out a way to use IRCODE NUM commands somehow.


----------



## telemark (Nov 12, 2013)

Sorry, I'm a Linux / Mac scripter. I would have to install Windows just to try the software you mentioned.

Yes, SETCH has been reported to not work, so IRCODE is the only way last I heard for the second part.

If you install Perl or Python on your windows machine, you might get more responses.


----------



## telemark (Nov 12, 2013)

This works in Linux, might work on other Perl platforms with netcat or a unix like telnet installed.


Spoiler





```
$ cat pokeMinis.pl 

#!/usr/bin/perl
use warnings;
use strict;
use IO::Handle;

my %map = (
  "192.168.0.100" => "1352",
  "192.168.0.101" => "1500"
);

my $port = '31339';
my $cmd = "nc ";
#my $cmd = "telnet ";


foreach my $ip (keys(%map)) {
  print "$ip:\n";
  open SOCK, "|$cmd $ip $port";
  SOCK->autoflush(1);
  my $channel = $map{$ip};
  sleep 2;
  print SOCK "IRCODE LIVETV\r";
  sleep 1;
  my @digits = split(//, $channel);
  foreach my $digit (@digits) {
    print SOCK "IRCODE NUM$digit\r";
    sleep 1;
  }
  close SOCK;
  sleep 1;
}
```




Or Python:


Spoiler





```
$ cat pokeMinis.py

#!/usr/bin/env python
 
import socket
import time
 
hosts = (
  ("192.168.0.100", "1352"),
  ("192.168.0.101", "1500")
)
port = 31339
 
for ip, channel in hosts:
  print("%s:" % ip)
  s = socket.socket()
  s.connect((ip, port))

  time.sleep(2) 
  s.sendall("IRCODE LIVETV\r")
  time.sleep(2)
 
  for digit in channel:
    s.sendall("IRCODE NUM%s\r" % digit)
    time.sleep(1)
 
  s.close()
```



Or use as a template for other languages.

```
IRCODE LIVETV
IRCODE NUM1
IRCODE NUM5
IRCODE NUM0
IRCODE NUM0

IRCODE LIVETV
IRCODE NUM1
IRCODE NUM3
IRCODE NUM5
IRCODE NUM2
```


----------



## telemark (Nov 12, 2013)

Oh wait a sec, why are you setting the channel on the Mini's instead of leaving them on the channel they're on?


----------



## HuskerMike (Jun 16, 2014)

The reason for the channel input is so that each day, all the TVs would default back to their correct news channels for work-time regardless of what channel they recorded the night before. Not as necessary as the stay-awake aspect, but I thought it would be useful. I'll keep working on this today.


----------



## jntc (Dec 5, 2013)

Is there something to do on the mini's to open the port? Port 31339 isn't open on any of the 5 I have.

# nmap 192.168.0.30

Starting Nmap 6.46 ( http://nmap.org ) at 2015-01-20 13:32 EST
Nmap scan report for xxxxxx.xxxxxx.com (192.168.0.30)
Host is up (0.0053s latency).
Not shown: 995 filtered ports
PORT STATE SERVICE
80/tcp open http
443/tcp open https
2190/tcp open tivoconnect
2191/tcp open tvbus
9080/tcp closed glrpc
MAC Address: 00:119:xx:xx:xx (TiVo)


----------



## Arcady (Oct 14, 2004)

Did you turn on "network remote control" in the settings? I don't think port 31339 is turned on until you do that.


----------



## jntc (Dec 5, 2013)

Arcady said:


> Did you turn on "network remote control" in the settings? I don't think port 31339 is turned on until you do that.


That would be it! Thanks!


----------



## weedwhacker2 (Sep 8, 2013)

Any update? I have tried the same things with no good results changing the channel on the mini.. Would be nice to have the news on without finding the remote 



HuskerMike said:


> The reason for the channel input is so that each day, all the TVs would default back to their correct news channels for work-time regardless of what channel they recorded the night before. Not as necessary as the stay-awake aspect, but I thought it would be useful. I'll keep working on this today.


----------



## METTTAL (Oct 6, 2010)

Can anyone help me with this? I'm trying to do the same thing, and use the python script provided (I don't know anything about python, and very little about programming), but I'm getting an error when running it:

Traceback (most recent call last):
File "N:\Tivo\602.py", line 17, in <module>
s.sendall("IRCODE LIVETV\r")
TypeError: a bytes-like object is required, not 'str'
>>>

Any help would be appreciated it. I'm searching the error, but knowing nothing about python programming isn't helping me fix it.

***************
EDIT: Nevermind, I found a page that assisted me in figuring it out.

Needed to change:

s.sendall("IRCODE LIVETV\r")

TO

s.sendall("IRCODE LIVETV\r".encode(encoding='utf_8'))

Also had to do that for the number send:

s.sendall("IRCODE NUM%s\r".encode(encoding='utf_8') % digit.encode(encoding='utf_8'))


----------



## richie_p (Feb 18, 2017)

echo IRCODE STANDBY | telnet 192.168.0.10 31339


----------

