Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-11-2019, 09:37 AM
GuitarDude GuitarDude is offline
Registered User
 
Join Date: Mar 2019
Posts: 8
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
  #2  
Old 03-11-2019, 10:53 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
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.
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #3  
Old 03-11-2019, 11:24 AM
GuitarDude GuitarDude is offline
Registered User
 
Join Date: Mar 2019
Posts: 8
Thumbs up Web Interface Script

Quote:
Originally Posted by berdmann View Post
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.
  #4  
Old 03-11-2019, 11:49 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
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
__________________
Thanks,
--Brittney

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

Last edited by berdmann; 03-11-2019 at 12:08 PM.
  #5  
Old 03-11-2019, 12:20 PM
GuitarDude GuitarDude is offline
Registered User
 
Join Date: Mar 2019
Posts: 8
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.
  #6  
Old 03-11-2019, 03:47 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
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"?
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #7  
Old 03-12-2019, 06:08 AM
GuitarDude GuitarDude is offline
Registered User
 
Join Date: Mar 2019
Posts: 8
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.
  #8  
Old 03-12-2019, 09:14 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
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.
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #9  
Old 03-12-2019, 09:19 AM
GuitarDude GuitarDude is offline
Registered User
 
Join Date: Mar 2019
Posts: 8
Talking

Quote:
Originally Posted by GuitarDude View Post
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.
  #10  
Old 03-12-2019, 09:59 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
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.
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #11  
Old 03-12-2019, 10:52 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
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
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #12  
Old 03-12-2019, 11:07 AM
GuitarDude GuitarDude is offline
Registered User
 
Join Date: Mar 2019
Posts: 8
Quote:
Originally Posted by berdmann View Post
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
Closed Thread

Tags
scripts , website

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 09:37 AM.