Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 2.33 average. Display Modes
  #16  
Old 01-19-2007, 07:53 AM
eazy2001x eazy2001x is offline
Registered User
 
Join Date: Jan 2007
Posts: 17
Very nice...

I changed the code to this..

Code:
Dim us, ps
us = crt.dialog.prompt("Please Enter Your Username")
ps = crt.dialog.prompt("Please Enter Your Password:","Enter Password","",True)

And it blocks out the password as i type it in.

Thanks a million....
Reply With Quote
  #17  
Old 01-19-2007, 09:05 AM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 819
No problem. I'm glad that works for you.

JJH
Reply With Quote
  #18  
Old 01-19-2007, 03:31 PM
eazy2001x eazy2001x is offline
Registered User
 
Join Date: Jan 2007
Posts: 17
Another issue I have is with the connection method part of the script. I have a few older Cisco routers out there that require me to log in with SSH1. Now when I change the script to SSH1 it doesn’t connect to the host then attempts the next IP in line.

Here is the code:
Code:
        ' Choose your connect method
        '
        ' the use of the /Telnet connection method will require additional logic for
        ' detecting the username and password prompts (using crt.screen.WaitForString)
        ' and entering these values in order to authenticate successfully before running
        ' any commands.        '
        '      crt.session.connect "/Telnet " & szHost
        '
        crt.session.connect "/SSH1 /ACCEPTHOSTKEYS /L "& us &" /PASSWORD "& ps &" /Z 6 " & szHost
        '
        ' The following connection method requires that the values in g_vHosts are session
        ' names, rather than hostnames or IP addresses
        ' crt.session.connect "/S " & szHost
I have also tried this:

Code:
crt.session.connect "/SSH1 /ACCEPTHOSTKEYS /L "& us &" /PASSWORD "& ps &" /Z 6 " & szHost
and this:

Code:
crt.session.connect "/SSH1 /L "& us &" /PASSWORD "& ps &" /Z 6 " & szHost
Now if I go to the command prompt and type in all the commands manually I can connect just fine.

This is what I type in the command line:

Code:
securecrt /ssh1 /accepthostkeys /c 3des /l user /password password 192.168.1.2
Once connected I do notice that it connected on SSH1:3DES

So I tried this:

Code:
crt.session.connect "/SSH1 /c 3des /L "& us &" /PASSWORD "& ps &" /Z 6 " & szHost
None of them work on SSH1. Now I did notice that it takes a tad bit longer to log in on SSH1. Any help will be greatly appreciated, Thanks again in advanced.
Reply With Quote
  #19  
Old 01-22-2007, 11:26 AM
eazy2001x eazy2001x is offline
Registered User
 
Join Date: Jan 2007
Posts: 17
Do you guys think I need to add something extra for SSH1 to work? I tried so many other things and I canít get it to work. What about adding a longer hold time to wait for the connection to be established before it logs into the next IP address.
Reply With Quote
  #20  
Old 01-22-2007, 05:03 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 819
Hi Eazy.

We have found that some Cisco routers don't handle
compression very well - especially with SSH1. The /Z flag in
your command is specifying a compression level.

Do you get better behavior if you remove the /Z and it's
compression value from your command?

Thanks
JJH

Last edited by jjh; 01-22-2007 at 05:36 PM.
Reply With Quote
  #21  
Old 01-23-2007, 01:05 PM
eazy2001x eazy2001x is offline
Registered User
 
Join Date: Jan 2007
Posts: 17
J thanks again.. it worked on the first try :-)

New Code:
Code:
crt.session.connect "/SSH1 /ACCEPTHOSTKEYS /L "& us &" /PASSWORD "& ps &" "& szHost &""
Now I believe have a formatting or placement problem. I successfully able to join the three scripts into one big script.. Well 2/3 parts successfully.

I am having a problem integrating the Nslookup script into the multiple login script. When I add it I can only hit the first nResult error 0 which was labeled as "This Router Is A SSH Enabled Device (Cisco/CPE)" before. Now I want it to be used to continue on so I used this:

Code:
If nResult = 0 then
Which follows the rest of the commands.

Now i wanted to add "If nResult = 1 then" go to next ip on list. something like

Code:
If nResult = 1 then next

Here is my current code with all three scripts:

Code:
#$language = "VBScript"
#$interface = "1.0"
' ConnectToMultipleHostsAndSendCommands.vbs
'
Dim us, ps
us = crt.dialog.prompt("Please Enter Your Username")
ps = crt.dialog.prompt("Please Enter Your Password:","Enter Password","",True) 

'Option Explicit

Dim g_shell, g_fso
Set g_shell = CreateObject("WScript.Shell")
Set g_fso   = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

' array of target hosts to which we will be connecting
dim g_vHosts(7)

g_vHosts(0) = "192.168.1.100"
g_vHosts(1) = "192.168.1.3"
g_vHosts(2) = "192.168.1.4"
g_vHosts(3) = "192.168.1.5"
g_vHosts(4) = "192.168.1.162"
g_vHosts(5) = "192.168.1.163"
g_vHosts(6) = "192.168.1.178"


' List of commands that we will issue on each host after
' we are connected
dim g_vCommands(7)
g_vCommands(1) = "config t" & vbCr
g_vCommands(2) = "file prompt quiet" & vbCr
g_vCommands(3) = "end" & vbcr
g_vCommands(4) = "copy start tftp://192.168.1.100" & vbcr
g_vCommands(5) = "config t" & vbCr
g_vCommands(6) = "no file prompt quiet" & vbCr
g_vCommands(7) = "end" & vbcr & vbcr

Dim g_szPrompt
g_szPrompt = "#"

Dim g_szLogNameTemplate
g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY - HOST.log"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()

    crt.screen.synchronous = true

    Dim nIndex, szHost
    For nIndex = 0 to uBound(g_vHosts) - 1
        szHost = g_vHosts(nIndex)

        ' Reset logging to 'off'
        crt.session.Log False

        ' Disconnect from any previous connection we have made
        If crt.Session.Connected = True then
            crt.session.Disconnect
        end if

        ' Set a log file name for this next connection
        Dim szLogFilename
        szLogFilename = g_szLogNameTemplate
        szLogFilename = Replace(szLogFilename, "HOST", szHost)
        szLogFilename = Replace(szLogFilename, "MM", NN(Month(Now)))
        szLogFilename = Replace(szLogFilename, "DD", NN(Day(Now)))
        szLogFilename = Replace(szLogFilename, "YYYY", Year(Now))

        crt.session.logfilename = szLogFilename

        On Error Resume Next

        ' Turn on logging for this connection
        crt.session.log True

        ' Choose your connect method
        '
        ' the use of the /Telnet connection method will require additional logic for
        ' detecting the username and password prompts (using crt.screen.WaitForString)
        ' and entering these values in order to authenticate successfully before running
        ' any commands.        '
        '      crt.session.connect "/Telnet " & szHost
        '
    Dim szRemoteAddress
    szRemoteAddress = crt.Session.RemoteAddress

    ' Run Searches for Telnet Active (port 23)
    szCmd = "cmd /C nmap.exe " & szHost & " -p 23|find ""closed"">nul"
    Set objShell = CreateObject("WScript.Shell")
    nResult = objShell.Run(szCmd, 5, True)

    Dim startlgn

    If nResult = 0 then
    If nResult = 1 then next

crt.session.connect "/SSH1 /ACCEPTHOSTKEYS /L "& us &" /PASSWORD "& ps &" "& szHost &""

            ' We've connected successfully. Let's issue commands
            Dim nCommandIndex
            For nCommandIndex = 0 to UBound(g_vCommands) - 1
                crt.Screen.Send g_vCommands(nCommandIndex) & vbcr

                ' Wait for the command to complete. If you want this to time out
                ' after a number of seconds, provide a timeout value to the WaitForString
                ' command as in:
                '     nResult = crt.Screen.WaitForString(g_szPrompt, 100)
                '
                ' This type of construct will wait for the value of g_szPrompt for 100 seconds
                ' and return false if the timeout occurs before the prompt string is detected.
                '
                ' For this example, we'll just wait forever.
                'crt.Screen.WaitForString g_szPrompt

                crt.Screen.WaitForString g_szPrompt,5
            Next

        End if

        ' Disconnect from the current connection we have made and turn off logging
        If crt.Session.Connected = True then
            crt.session.Log False
            crt.session.Disconnect
        end if

    Next

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber)
' Normalizes a single digit number to have a 0 in front of it
    NN = nNumber
    If nNumber < 10 Then NN = "0" & nNumber
End Function
Reply With Quote
  #22  
Old 01-23-2007, 03:35 PM
eazy2001x eazy2001x is offline
Registered User
 
Join Date: Jan 2007
Posts: 17
Ok,

I was able to take care of that and another problem by using the following code:

Code:
#$language = "VBScript"
#$interface = "1.0"
' ConnectToMultipleHostsAndSendCommands.vbs
'
Dim us, ps
us = crt.dialog.prompt("Please Enter Your Username")
ps = crt.dialog.prompt("Please Enter Your Password:","Enter Password","",True) 

'Option Explicit

Dim g_shell, g_fso
Set g_shell = CreateObject("WScript.Shell")
Set g_fso   = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

' array of target hosts to which we will be connecting
dim g_vHosts(7)

g_vHosts(0) = "192.168.1.100"
g_vHosts(1) = "192.168.1.3"
g_vHosts(2) = "192.168.1.4"
g_vHosts(3) = "192.168.1.5"
g_vHosts(4) = "192.168.1.162"
g_vHosts(5) = "192.168.1.163"
g_vHosts(6) = "192.168.1.178"


' List of commands that we will issue on each host after
' we are connected
dim g_vCommands(7)
g_vCommands(0) = "config t" & vbCr
g_vCommands(1) = "file prompt quiet" & vbCr
g_vCommands(2) = "end" & vbcr
g_vCommands(3) = "copy start tftp://192.168.1.100" & vbcr
g_vCommands(4) = "config t" & vbCr
g_vCommands(5) = "no file prompt quiet" & vbCr
g_vCommands(6) = "end" & vbcr & vbcr

Dim g_szPrompt
g_szPrompt = "#"

Dim g_szLogNameTemplate
g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY - HOST.log"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()

    crt.screen.synchronous = true

    Dim nIndex, szHost
    For nIndex = 0 to uBound(g_vHosts) - 1
        szHost = g_vHosts(nIndex)

        ' Reset logging to 'off'
        crt.session.Log False

        ' Disconnect from any previous connection we have made
        If crt.Session.Connected = True then
            crt.session.Disconnect
        end if

        ' Set a log file name for this next connection
        Dim szLogFilename
        szLogFilename = g_szLogNameTemplate
        szLogFilename = Replace(szLogFilename, "HOST", szHost)
        szLogFilename = Replace(szLogFilename, "MM", NN(Month(Now)))
        szLogFilename = Replace(szLogFilename, "DD", NN(Day(Now)))
        szLogFilename = Replace(szLogFilename, "YYYY", Year(Now))

        crt.session.logfilename = szLogFilename

        On Error Resume Next

        ' Turn on logging for this connection
        crt.session.log True

        ' Choose your connect method
        '
        ' the use of the /Telnet connection method will require additional logic for
        ' detecting the username and password prompts (using crt.screen.WaitForString)
        ' and entering these values in order to authenticate successfully before running
        ' any commands.        '
        '      crt.session.connect "/Telnet " & szHost
        '
    Dim szRemoteAddress
    szRemoteAddress = crt.Session.RemoteAddress

    ' Run Searches for Telnet Active (port 23)
    szCmd = "cmd /C H:\ROUTER~1\FINAL_~1\nmap.exe " & szHost & " -p 23|find ""closed"">nul"
    Set objShell = CreateObject("WScript.Shell")
    nResult = objShell.Run(szCmd, 5, True)

    Dim nextt
    If nResult = 0 then nextt
    if nResult = 1 then msgbox ("hello " & szHost)

'nextt
crt.session.connect "/SSH1 /ACCEPTHOSTKEYS /L "& us &" /PASSWORD "& ps &" "& szHost &""

            ' We've connected successfully. Let's issue commands
            Dim nCommandIndex
            For nCommandIndex = 0 to UBound(g_vCommands) - 1
                crt.Screen.Send g_vCommands(nCommandIndex) & vbcr
                nResult = crt.Screen.WaitForString(g_szPrompt, 10)

                ' Wait for the command to complete. If you want this to time out
                ' after a number of seconds, provide a timeout value to the WaitForString
                ' command as in:
                '     nResult = crt.Screen.WaitForString(g_szPrompt, 100)
                '
                ' This type of construct will wait for the value of g_szPrompt for 100 seconds
                ' and return false if the timeout occurs before the prompt string is detected.
                '
                ' For this example, we'll just wait forever.
                'crt.Screen.WaitForString g_szPrompt

                crt.Screen.WaitForString g_szPrompt,5

            Next

        ' Disconnect from the current connection we have made and turn off logging
        If crt.Session.Connected = True then
            crt.session.Log False
            crt.session.Disconnect
        end if

    Next

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber)
' Normalizes a single digit number to have a 0 in front of it
    NN = nNumber
    If nNumber < 10 Then NN = "0" & nNumber
End Function
One problem that I had was the commands being issues way too fast so I needed to add:

Code:
nResult = crt.Screen.WaitForString(g_szPrompt, 10)
The other problem was resolved by adding changing this part around:

Code:
    Dim szRemoteAddress
    szRemoteAddress = crt.Session.RemoteAddress

    ' Run Searches for Telnet Active (port 23)
    szCmd = "cmd /C H:\ROUTER~1\FINAL_~1\nmap.exe " & szHost & " -p 23|find ""closed"">nul"
    Set objShell = CreateObject("WScript.Shell")
    nResult = objShell.Run(szCmd, 5, True)

    Dim nextt
    If nResult = 0 then nextt
    if nResult = 1 then msgbox ("hello " & szHost)

'nextt
crt.session.connect "/SSH1 /ACCEPTHOSTKEYS /L "& us &" /PASSWORD "& ps &" "& szHost &""

            ' We've connected successfully. Let's issue commands
            Dim nCommandIndex
            For nCommandIndex = 0 to UBound(g_vCommands) - 1
                crt.Screen.Send g_vCommands(nCommandIndex) & vbcr
                nResult = crt.Screen.WaitForString(g_szPrompt, 10)

                ' Wait for the command to complete. If you want this to time out
                ' after a number of seconds, provide a timeout value to the WaitForString
                ' command as in:
                '     nResult = crt.Screen.WaitForString(g_szPrompt, 100)
                '
                ' This type of construct will wait for the value of g_szPrompt for 100 seconds
                ' and return false if the timeout occurs before the prompt string is detected.
                '
                ' For this example, we'll just wait forever.
                'crt.Screen.WaitForString g_szPrompt

                crt.Screen.WaitForString g_szPrompt,5

            Next

        ' Disconnect from the current connection we have made and turn off logging
        If crt.Session.Connected = True then
            crt.session.Log False
            crt.session.Disconnect
        end if

    Next

End Sub
Now Iím hoping to replace the error level 1 command with a second set of commands to log into my telnet enabled devices.

Code:
if nResult = 1 then msgbox ("hello " & szHost)
How do things look? I hope good, if you have any suggestions I will be more than grateful, thanks in advanced.
Reply With Quote
  #23  
Old 01-23-2007, 04:57 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 819
It looks like you have a handle on things. I think your
script will work.

Thanks
JJH
Reply With Quote
  #24  
Old 01-26-2007, 05:05 AM
Grunt11B's Avatar
Grunt11B Grunt11B is offline
Registered User
 
Join Date: Aug 2006
Posts: 22
Lightbulb

I think the VanDyke ClientTools and Windows PowerShell would be a good solution to this as well. I ran into something similar; I also wanted to grab output from a VSH command into a script. The VB script was getting a bit lengthy and the PowerShell function was only a few lines long.

Call the function from another script or from the interactive terminal to get what you're looking for. It comes in real handy when searching 1200+ configs looking to see which ones have some feature enabled or whatever.

Anyway, here's the function to return the output of the command to a local file for later viewing:

Function sparcf {
$now = get-date -format yyyyMMdd.HHmm.ss.\tx\t
$strFilename = "/tftpboot/" + $args[1]
vsh user@host grep -l $args[0] $strFilename | Out-File $now
$sparcfile = ls -name $now
}

Anyway, here's the function to return the output of the command to the terminal window:

Function sparct {
$strFilename = "/tftpboot/" + $args[1]
vsh user@host grep -l $args[0] $strFilename | Write-Host
}

Windows PowerShell: http://www.microsoft.com/technet/scr.../hubs/msh.mspx

VanDyke ClientTools: Contact VanDyke Support

Cheers,

-Christopher
__________________
-Christopher
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 08:54 PM.