[Tutor] python telnet

Rayon evosweet at hotmail.com
Sun Nov 20 00:42:28 CET 2011


Hi all got my code to work. 
I used an in queue and an out queue passed it to the telnet session . 
I am sending commands to the in_q  using sockets and passing them back data
with the out_q. 
Below is the code for a nonstop python telnet session. 
Thanks for the help, it got me thinking and that was worth it. 

def end_less():
    """
    Start telnet session and never stop it :) 
    """
    global host
    global cmd_q
    global out_q 
    message = """
        HLR DOWN ERROR
        """
    try: 
        hia_tel = telnetlib.Telnet(host)
        hia_tel.set_debuglevel(1)
        hia_tel.read_until("login:")
        hia_tel.write('maint'+"\r")
        hia_tel.read_until("Password:")
        hia_tel.write("maint"+"\r")
        hia_tel.read_until("maint at atcaHLRds0 /public/users/maint>")
        while 1:
          try: 
            command = cmd_q.get()
            hia_tel.write(command+"\r")
            data = hia_tel.read_until("maint at atcaHLRds0
/public/users/maint>")
            out_q.put(data)
          except Exception,error:
            error_email_mis(message)
            logs('error',str(error),'null')
            end_less()
            time.sleep(10)
    except Exception,error:
        error_email_mis(message)
        logs('error',str(error),'null') 

-----Original Message-----
From: tutor-bounces+evosweet=hotmail.com at python.org
[mailto:tutor-bounces+evosweet=hotmail.com at python.org] On Behalf Of Rayon
Sent: 19 November 2011 08:41
To: 'James Chapman'; tutor at python.org
Subject: Re: [Tutor] python telnet

Thanks but still not working, I am wondering if I need to give the script
some kind of special permission to execute on windows 7.

-----Original Message-----
From: tutor-bounces+evosweet=hotmail.com at python.org
[mailto:tutor-bounces+evosweet=hotmail.com at python.org] On Behalf Of James
Chapman
Sent: 19 November 2011 08:23
To: tutor at python.org
Subject: Re: [Tutor] python telnet

traceback has:
 child = winspawn('telnet 192.168.0.55:210')

When using telnet from CLI (on windows), you would type:
telnet 192.168.0.55 210

Note the space between the IP and port number and not a :colon.

Not sure this is your problem but probably worth mentioning.

--
James


At Saturday, 19/11/2011 on 11:44 Rayon wrote:
> I used the turn on turn off feature, and I can start a telnet session 
> from the command line.
> 
> -----Original Message-----
> From: tutor-bounces+evosweet=hotmail.com at python.org
> [mailto:tutor-bounces+evosweet=hotmail.com at python.org] On Behalf Of 
> Steven D'Aprano
> Sent: 19 November 2011 07:04
> To: tutor at python.org
> Subject: Re: [Tutor] python telnet
> 
> Rayon wrote:
> > I installed the telnet client but still the same error. 
> 
> How did you install it? Windows includes a telnet application, but it 
> has to be enabled first:
> 
> http://windows.microsoft.com/en-AU/windows-vista/Telnet-frequently-ask
> ed-que
> stions
> 
> If you run "telnet" from the Windows shell (cmd.exe), what happens?
> 
> Until you can successfully run telnet from Windows, there isn't any 
> point trying to run it from Python.
> 
> 
> --
> Steven
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list