VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   python sending enter key over telnet (https://forums.vandyke.com/showthread.php?t=12491)

jakjok 09-25-2016 01:06 AM

python sending enter key over telnet
 
HI,


i'm not able to send "enter" key for after accessing the access server, i need to type the device name and hit enter ... till here its working .... after this .. i need to send another enter key .. looks like my script new line but not the enter key


Code:

objNewTab = crt.Session.ConnectInTab("/TELNET ###.###.#.## 23")

      if objNewTab.Session.Connected:
        objNewTab.Screen.Synchronous = True
        objNewTab.Screen.WaitForString("sername:")
                #objNewTab.Screen.Send(user1 + "\r")
                #objNewTab.Screen.Send(password + "\r")
                #objNewTab.Screen.Send("redacted" + "\r")
                #objNewTab.Screen.Send("redacted" + session + "\r")
        #objNewTab.Screen.Send("redacted" + rackNumber + session + "\r")
        objNewTab.Screen.Send(user1 + "\r")
        objNewTab.Screen.WaitForString("assword:")
        objNewTab.Screen.Send(password + "\r")
        objNewTab.Screen.Send("\r")
        objNewTab.Screen.Send("\r")
        objNewTab.Screen.Send("\r\n")
        objNewTab.Screen.Send("\n")
        objNewTab.Screen.Send("\n\r")
        objNewTab.Screen.Send(session) 
        objNewTab.Screen.Send("\r")  /// i need to send enter after this line ...
        objNewTab.Screen.Send("\n\r")
        objNewTab.Screen.Send("\r\n")
        objNewTab.Screen.Send("\r")
        objNewTab.Screen.Send("\r")
        #objNewTab.creen.sendKeys("[enter]")
        #objNewTab.Screen.Send(VbCr)
        #objNewTab.Screen.Send chr(13)
        objNewTab.Screen.Send(chr(13))
        objNewTab.Screen.Send('{ENTER}')
        objNewTab.Screen.Send(chr(13))
        objNewTab.Screen.Send("{ASC 065}")
        objNewTab.Screen.Send('{ASC 2709}')
        objNewTab.Screen.Send('{ASC 2709}')
        objNewTab.Screen.Send('{ASC 2709}')
        objNewTab.Screen.Send('{ASC 2709}')
        objNewTab.Screen.Send("{ASC 065}")
        objNewTab.Screen.Send("{ASC 065}")
        objNewTab.Screen.Send("{ASC 065}")
        objNewTab.Screen.Send("{ASC 065}")
        objNewTab.Screen.Send(chr(13))
        objNewTab.Screen.Send(chr(13))
        objNewTab.Screen.Send("\r")

...it shows that its sending new line . but not the enter KEY:

++++++++++++++++++++++++++++++
Code:


Username:

User Access Verification

Username: redacted
Password:                                                                                             


PDX-03#R1
Translating "R1"
Trying r1 address #1 ...
% Connection refused by remote host

PDX-03#
PDX-03#R4
Translating "R4"
Trying asa4 address #1 ... Open

+++++++++++++++++++++++++++++++++++++++


while it should send the enter KEY and i need to be like this :


Code:

Username:

User Access Verification

Username:redacted
Password:                                                                                             


PDX-03#R1
Translating "R1"
Trying r1 address #1 ...
% Connection refused by remote host

PDX-03#
PDX-03#R4
Translating "R4"
Trying asa4 address #1 ... Open



R4>



thanks in advance

bgagnon 09-26-2016 08:01 AM

Hi jakjok,

The "\r" (CR) does represent the ENTER key. However, if ENTER key means something special to your device, then you would normally use SendKeys(), except, unfortunately, as shown in SecureCRT's Help file, SendKeys() is not supported in Python:

Quote:

Python
Syntax
SendKeys is not currently supported for Python.

I have added this thread to a feature request in our product enhancement database for support for SendKeys() in Python. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #12491" in the subject line or use this form from the support page of our website.

Are you using SecureCRT/Windows and just choosing Python because it's more flexible?

jakjok 10-11-2016 05:31 PM

yup, python is more easy for me

also, i'm facing another issue now, and need your advice:


Quote:

outPut = crt.Screen.WaitForStrings ([ "error", ">", "#"], 1000)
index = crt.Screen.MatchIndex
crt.Screen.Send("!" + str(index) + "\r")

if (index == 2):
crt.Screen.Send("!" + str(index) + "\r")
crt.Screen.Send("en" + "\r")
pass

the index value should be 2 when we are on prompt mode while it shows me 3

Quote:

SW2>
SW2>
SW2>!3
SW2>
SW2>
if i removed "#" from the list it works fine , can you help me on this as well :)

bgagnon 10-12-2016 08:32 AM

Hi jakjok,

Have you set synchronous to True in your script?

This seems like a classic case of the script being out of sync. :)

Can you post the entire script (redacting sensitive data)?


All times are GMT -6. The time now is 07:35 PM.