VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Launching to Web Interfaces (https://forums.vandyke.com/showthread.php?t=13442)

GuitarDude 03-11-2019 09:37 AM

Launching to Web Interfaces
 
Trying to make my job a bit faster. When I open a command line of the device I want to open the Website interface of it as well. Here is what I have now. I'm not sure what I'm missing.
Also I want to have one script and just change the arguments within the properties of the devices to the specific IP.


# $language = "VBScript"
# $interface = "1.0"
' Run.vbs demonstrates how to utilize the Windows Scripting Host (WSH) by using
' its 'Run' method to execute other programs. Note the use of nested quotes to pass
' a path that contains spaces along with command line arguments.

Sub Main
Dim shell
Dim IP
Set shell = CreateObject("WScript.Shell")
shell.Run """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" https://&IP&:4434"

End Sub

berdmann 03-11-2019 10:53 AM

Hi GuitarDude,

You can get the IP address of the connected session using the RemoteAddress property of the Session object from SecureCRT's scripting API.

For Example:

Code:

# $language = "VBScript"
# $interface = "1.0"

strRemoteAddress = crt.Session.RemoteAddress

Set shell = CreateObject("WScript.Shell")
shell.Run("http://" & strRemoteAddress)

Does that work for you?

For more information about SecureCRT's scripting API please refer to the Help.

GuitarDude 03-11-2019 11:24 AM

Web Interface Script
 
Quote:

Originally Posted by berdmann (Post 51084)
Hi GuitarDude,

You can get the IP address of the connected session using the RemoteAddress property of the Session object from SecureCRT's scripting API.

For Example:

Code:

# $language = "VBScript"
# $interface = "1.0"

strRemoteAddress = crt.Session.RemoteAddress

Set shell = CreateObject("WScript.Shell")
shell.Run("http://" & strRemoteAddress)

Does that work for you?

For more information about SecureCRT's scripting API please refer to the Help.


This does work for me. Thanks for the help. I did change a few things like https and adding the port number.

berdmann 03-11-2019 11:49 AM

Hi GuitarDude,

Great! I am glad to hear that you are all set! My apologies for failing to include the port number in the example!

Do you run the script every time that you connect to a session?

If so, you can configure a logon script to run the script as soon as you connect in Options > Session Options > Connection > Logon Actions. Simply point to the script in the "Login Script" field.

If you do not wish to run the script every time that you connect, you can map a button on your Button Bar to run the script as you please.

For more information please refer to our YouTube video:

https://youtu.be/qp82UWxGB8I

GuitarDude 03-11-2019 12:20 PM

Web Interface Script
 
Looking into the button bar a little I just thought of another helpful button. It would be pinging the current session. What is the shell run for that.

berdmann 03-11-2019 03:47 PM

Hi GuitarDude,

Correct me if I am mistaken, but it sounds like you are trying to ping the remote that you are connected to. Is that correct?

Can you tell me more about the problem that you are trying to solve or the goal that you have as it relates to pinging the "current session"?

GuitarDude 03-12-2019 06:08 AM

Web Interface Script
 
The current session, is what I would like to ping. Continuously pinging the address til it is told to stop. ctrl + c is the break to stop a ping for windows. That should be fine.

berdmann 03-12-2019 09:14 AM

Hi GuitarDude,

It is not currently possible for SecureCRT to ping a remote. I would like to capture a feature request on your behalf to add this functionality.

Can you please elaborate on why or how this feature will improve your experience with SecureCRT?

As a work around, you may be able to automate pinging your remote hosts via CMD with a VBScript, perhaps a VBS forum would be a better resource.

GuitarDude 03-12-2019 09:19 AM

Quote:

Originally Posted by GuitarDude (Post 51095)
The current session, is what I would like to ping. Continuously pinging the address til it is told to stop. ctrl + c is the break to stop a ping for windows. That should be fine.


Sorry I meant to say if the system that I am running the SecureCRT send a ping to current session. Sorry if I wasn't clear about that.

berdmann 03-12-2019 09:59 AM

Hi GuitarDude,

You can run a script in SecureCRT to get the IP address using crt.Session.RemoteAddress and then launch CMD to do the ping.

Here is a general example:

Code:

strTarget = crt.Session.RemoteAddress

Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
strPingResults = LCase(objExec.StdOut.ReadAll)
myResponse = msgbox("Ping Results: " & vbcr & vblf & strPingResults)

As you can see, the only thing that is really specific to SecureCRT's scripting API is crt.Session.RemoteAddress. The rest of what you would like to do falls outside of SecureCRT.

We were not able to find a way to get CMD to display the ping results real time.

berdmann 03-12-2019 10:52 AM

Hi GuitarDude,

I stumbled upon this example, in which the ping will run continuously in CMD until you press CTRL+C

Code:

' Attempt to set strHost to some common-sense default
' values... first, see if anything is in the clipboard...
strHost = crt.Clipboard.Text
' If not, see if anything is selected in the terminal window...
If strHost = "" Then strHost = crt.Screen.Selection

' Set up a default command to run. If the button mapped to
' run this script doesn't have any arguments, then this will
' be what is launched...
strCmd = "cmd /C ping __HOST__ -t"
if crt.Arguments.Count > 0 Then
    strCmd = crt.Arguments(0)
end if

Sub Main()
    ' Prompt the individual for input as to what to use for __HOST__:
    ' strHost = crt.Dialog.Prompt("Command to run is:" & vbcrlf & vbcrlf & _
    '    vbtab & strCmd & vbcrlf & vbcrlf & _
    '    "What host would you like to run the command on?", "Command Runner", strHost)
    ' handle cancel
    strHost = crt.Session.RemoteAddress
    if strHost = "" Then Exit Sub

    ' Replace __HOST__ with what was supplied...
    strCmd = Replace(strCMD, "__HOST__", strHost)

    ' Now, run the command and tap into stdout...reading all the data until it exits...
    Set g_shell = CreateObject("WScript.Shell")
    ' replace /C with /K to keep CMD window open
    strCmd = Replace(strCMD, "/C", "/K")
    g_shell.Run strCmd

End Sub


GuitarDude 03-12-2019 11:07 AM

Quote:

Originally Posted by berdmann (Post 51100)
Hi GuitarDude,

You can run a script in SecureCRT to get the IP address using crt.Session.RemoteAddress and then launch CMD to do the ping.

Here is a general example:

Code:

strTarget = crt.Session.RemoteAddress

Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
strPingResults = LCase(objExec.StdOut.ReadAll)
myResponse = msgbox("Ping Results: " & vbcr & vblf & strPingResults)

As you can see, the only thing that is really specific to SecureCRT's scripting API is crt.Session.RemoteAddress. The rest of what you would like to do falls outside of SecureCRT.

We were not able to find a way to get CMD to display the ping results real time.

This does the trick just right. It would be nice to have the real time but as long as I see something, I'm okay with it. I really do like the message though. Gives all the information that I need


All times are GMT -6. The time now is 01:04 AM.