Telnet client library in Python? Send Telnet commands from XBMC?
#1
Question 
hello,

is there anyway to open a telnet connection with python from the xbox to a pc telnet server?

greets from germany
benny

:kickass:
Reply
#2
yes
it exists a telnet library inside python but not sure it's ok with xbmc
Reply
#3
Quote:yes
it exists a telnet library inside python but not sure it's ok with xbmc
if it's a library in python by default it should work with xbmc. if it doesn't, then i have some work todo Smile
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
(darkie @ nov. 22 2004,00:13 Wrote:
Quote:yes
it exists a telnet library inside python but not sure it's ok with xbmc
if it's a library in python by default it should work with xbmc. if it doesn't, then i have some work todo Smile
you have some work to do Wink

importing of telnetlib works, but i can't open a telnet connection Sad

when i'm home from work i will poste some code.
Reply
#5
yeah, do your thing darkie Smile
Reply
#6
nice things to do with telnet Smile

- remot control your server, shutdown, reboot, etc...
- control linux vdr (video disk recorder which is a very popular project in germany to watch digital tv over http streams, etc. all you need is a dvb-c, dvb-t or dvb-s tv-card)

with telnet i could get epg (electronical program guide) data, switch channels, start & stop recordings.

greets
benny
Reply
#7
wow! looks like linvdr is exactly what everyone with a dvb-c/dvb-s card needs Smile
Reply
#8
this is the python.org example for a telnet session.
Quote:import getpass
import sys
import telnetlib

host = "localhost"
user = raw_input("enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.telnet(host)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("password: ")
tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()

Quote:#!python

import xbmc, xbmcgui, telnetlib

tn = telnetlib.telnet(192.168.111.1,2001)
tn.close()

dialog.ok("message", "ok")

this should open a telnet connection and close it directly, and then the messagebox should open.

but the message box only appears if i remove the 2 telnet lines No

Quote:#!python

import xbmc, xbmcgui, telnetlib

dialog.ok("message", "ok")

:help:
Reply
#9
shouldn't it be
Quote:tn = telnetlib.telnet("192.168.111.1", 2001)
instead? (i.e. with double quotes around the ip address.)
Reply
#10
omfg, it works Confused

thank you :thumbsup:
Reply
#11
i am a ubernewb when it comes to python scripting for xbmc. i'm looking for a simple python script that can do the following:

open a network connection on host - port 1399

send a string to the connection
recieve the returned data as a string
display this data on a window control
close the connection by sending a "quit"

i can currently communicate with the server by using the telnet client and interactively typing the commands. so what i'm trying to do is just emulate the telnet client programmatically. i know that there is a telnetlib library that might work.

anyone help?

thanks



Reply
#12
both the yac script and the wake-on-lan script show examples of establishing sockets and sending/receiving data etc... check xbmcscripts.com for links (it looks down now?).

it's not really all that hard.
http://www.python.org/doc/2.3/lib/module-socket.html
Reply
#13
i know that it looks simple, but i literally have no experience writing python scripts so any help is very appreciated. i was looking through python documentation and it looks like there is also a telnetlib class that i can potentially use?

as the tsreader control server can allow a telnet client to interact with it (tested this with command prompt), is there someone that can show me an easy example that provides the above listed functionality? i can probably figure it out from there. if comments are included it would make it a lot easier to figure out too.


thanks again in advance... i'm just trying to write this interface myself so i don't have to rely on the uberdevs.

jt
Reply
#14
here is a sample script that i created trying to achieve this, unfortunately this hangs the xbox script, and also hangs the control server...! so much for getting ahead.

is there any debugging functions i can incorporate to see what is happening here?

thanks.

Quote:import xbmc, xbmcgui
import telnetlib
import sys
#set host variables
host = "192.168.1.105"
port = 1399

#get actioncodes from keymap.xml
action_previous_menu = 10

class myclass(xbmcgui.window):
def (self):
self.stractioninfo = xbmcgui.controllabel(100, 120, 200, 200, '', 'font13', '0xffff00ff')
self.addcontrol(self.stractioninfo)
self.stractioninfo.setlabel('push back to quit')
self.button0 = xbmcgui.controlbutton(350, 500, 80, 30, "hello")
self.addcontrol(self.button0)
self.setfocus(self.button0)

def onaction(self, action):
if action == action_previous_menu:
telnet.write("quit" + "\n")
telnet.close
self.close()

def oncontrol(self, control):
if control == self.button0:
telnet = telnetlib.telnet(host, port)
telnet.read_until("control server")
telnet.write("help" + "\n")
msg = telnet.read_all()
self.message(msg)

def message(self, message):
dialog = xbmcgui.dialog()
dialog.ok(" my message title", message)

mydisplay = myclass()
mydisplay .domodal()
del mydisplay
Reply
#15
Reply

Logout Mark Read Team Forum Stats Members Help
Telnet client library in Python? Send Telnet commands from XBMC?0