Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-01-2019, 12:00 PM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 116
try different passwords

I have this script that works great to do different things

but lately there were some hosts that have old passwords .,. pass2 and pas3

I trying to add a simple way for it to try pass2 and pass3 if needed until it gets to
crt.Screen.WaitForString("]# ")

any advice / help is welcome.


Code:
# $language = "python"
# $interface = "1.0"

def main():
        crt.Screen.Synchronous = False
with open('/hosts') as hosts_:
        for host in hosts_:
                crt.Screen.WaitForString("working # ")
                crt.Screen.Send("ssh -oStrictHostKeyChecking=no root@" + host + '\r')
                crt.Screen.WaitForString("word: ")
                crt.Screen.Send("pass1" + chr(13))

                crt.Screen.WaitForString("]# ")
                crt.Screen.Send("uname -a;df -h" + chr(13))
                crt.Screen.WaitForString("]# ")
                crt.Screen.Send("exit" + chr(13))

main()
Reply With Quote
  #2  
Old 02-01-2019, 05:42 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
Hi rleon,

We do not have a script example that shows exactly how to accomplish this.

You may be able to modify our "Jump Host - Handle Secondary Host Connection Attempts" script to try more than one password for each host. Please refer to the following link:

https://forums.vandyke.com/showpost....62&postcount=1

If time and resources becomes available we might be able to provide a specific example as to how you could accomplish this. We will be sure to post the example here if that is the case.

Have a great day!
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 02-02-2019, 07:25 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 116
Thank you i tried that

I replaced

With my promit

Code:
strJumpHostPrompt = "# "
And I get the error ..

Code:
ScriptError

Error: Connection lost

File: /Users/rleon/crt_scripts/nfs2/test2.py
Line: 44

        crt.Screen.WaitForString(strCommand + "\r\n")


If i can get this work it would be great .. but the only thing is i have 100's of hosts

Reading from a list would make this script ideal.

Code:
with open('/Users/rleon/hosts') as hosts_:
        for host in hosts_:
Reply With Quote
  #4  
Old 02-02-2019, 11:02 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 116
I took the script and stripped out some stuff made sure the indents were ok.

when i run it .. it doesnt fall into any of the if statements

Any help would be appreciated.

ssh root@test
ssh root@test
ssh root@test
ssh root@test
ssh root@test
ssh root@test
ssh root@test
ssh root@test
ssh root@test
ssh root@test
ssh root@test
root@test's password:
Permission denied, please try again.
root@test's password:


Code:
# $language = "python"
# $interface = "1.0"

import SecureCRT

crt.Screen.Synchronous = True

def main():
        vHosts = [\
                "test",
                "test2",
                "test3",
                "test4"]

        vPossibleResponses = [\
                "]# ",
                "ogin:",
                "(yes/no)?",
                "sword: ",
                "timed out"]

        nIndex = 0
        strJumpHostPrompt = "# "

        while nIndex <= len(vHosts):
                strCommand = "ssh root@" + vHosts[nIndex]
                crt.Screen.Send(strCommand + "\r")
                crt.Screen.WaitForString(strCommand + "\r\n")

        while True:
                crt.Screen.WaitForStrings(vPossibleResponses)
                if crt.Screen.MatchIndex > 0:
                        strStringFound = vPossibleResponses[crt.Screen.MatchIndex - 1]

                if crt.Screen.MatchIndex == 1:
                        crt.Screen.Send("uname -a" + chr(13))
                        crt.Screen.WaitForString("]# ")
                        crt.Screen.Send("exit" + chr(13))

                        crt.Screen.WaitForString(strJumpHostPrompt)
                        break

                elif crt.Screen.MatchIndex == 2:
                        crt.Screen.Send("rleon16" + chr(13))

                elif crt.Screen.MatchIndex == 3:
                        crt.Screen.Send("yes\r")

                elif crt.Screen.MatchIndex == 4:
                        crt.Screen.Send("SomePass" + chr(13))

                elif crt.Screen.MatchIndex == 5:
                        crt.Screen.WaitForString(strJumpHostPrompt)
                        break
                else:
                        crt.Dialog.MessageBox("Yikes!\r\n\r\n"
                        "We never expect to get here.\r\n"
                         "\t" + strStringFound)
                        crt.Screen.SendSpecial("MENU_SCRIPT_CANCEL")

        nIndex = nIndex + 1
main()
Reply With Quote
  #5  
Old 02-04-2019, 01:22 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
Hi rleon,

You have entered an infinite while loop, resulting in your SSH command being sent repeatedly.

We have modified the script example that I mentioned in my previous response to iterate over multiple usernames and passwords.

Please re-download and test with the modified script example:

https://forums.vandyke.com/showpost....62&postcount=1

Please let me know if you have any specific questions regarding the modified script.
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 03:04 PM.