#1
|
|||
|
|||
Problem with SetOption for port forwards
Greetings,
I am having problems with scripting port forwards. The script below says it added the port forwarding but when you check current session options they are not there and testing the forwarding doesn't work. But if you rerun the script while still connected in the same the port forwarding gets added and works. I am on SecureCRT ver 7.3.7. Code:
# $language = "VBScript" # $interface = "1.0" Set objTab = crt.GetScriptTab Set objConfig = objTab.Session.Config Sub Main objTab.Screen.Synchronous = True objTab.Screen.IgnoreEscape = True if objTab.session.connected = false then edgemarkIP = crt.Dialog.Prompt("Please supply the IP of the Edgemark", "Need Information", "", False) edgemarkUser = crt.Dialog.Prompt("Please supply the Edgemark Username", "Need Information", "", False) edgemarkPass = crt.Dialog.Prompt("Please supply the Edgemark Password", "Need Information", "", True) objTab.session.Connect("/SSH2 /PASSWORD " & edgemarkPass & " " & edgemarkUser & "@" & edgemarkIP), True edgemarkIP = objTab.session.RemoteAddress objTab.screen.WaitForString "Service Type" ' Replace with your default prompt objTab.screen.send(vbCrLf) else objTab.screen.send(vbCrLf) end if objConfig.setOption "Port Forward Table V2", Split("10.20.32.8|5500|1|10.20.32.8|80||,10.20.32.13|5501|1|10.20.32.13|80||", ",") vPortForwards = objConfig.GetOption("Port Forward Table V2") nElements = UBound(vPortForwards) If nElements = -1 Then MsgBox "No port forward configuration defined" Else MsgBox nElements + 1 & _ " port forward entries exist in this session (" & _ objTab.Session.Path & ")" End If End Sub |
#2
|
|||
|
|||
Hi Yuuichi,
It appears there was an issue when trying to use the script when you are not currently connected to a session. It seems to stem from getting the Config of the tab prior to connecting to a session. I've added one line to get the Config after the connection is completed. This seems to resolve the issue in my testing. Does the change work for you? Code:
# $language = "VBScript" # $interface = "1.0" Set objTab = crt.GetScriptTab Set objConfig = objTab.Session.Config Sub Main objTab.Screen.Synchronous = True objTab.Screen.IgnoreEscape = True if objTab.session.connected = false then edgemarkIP = crt.Dialog.Prompt("Please supply the IP of the Edgemark", "Need Information", "", False) edgemarkUser = crt.Dialog.Prompt("Please supply the Edgemark Username", "Need Information", "", False) edgemarkPass = crt.Dialog.Prompt("Please supply the Edgemark Password", "Need Information", "", True) objTab.session.Connect("/SSH2 /PASSWORD " & edgemarkPass & " " & edgemarkUser & "@" & edgemarkIP), True edgemarkIP = objTab.session.RemoteAddress objTab.screen.WaitForString "Service Type" ' Replace with your default prompt objTab.screen.send(vbCrLf) else objTab.screen.send(vbCrLf) end if Set objConfig = objTab.Session.Config objConfig.setOption "Port Forward Table V2", Split("10.20.32.8|5500|1|10.20.32.8|80||,10.20.32.13|5501|1|10.20.32.13|80||", ",") vPortForwards = objConfig.GetOption("Port Forward Table V2") nElements = UBound(vPortForwards) If nElements = -1 Then MsgBox "No port forward configuration defined" Else MsgBox nElements + 1 & _ " port forward entries exist in this session (" & _ objTab.Session.Path & ")" End If End Sub
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
That worked! Thank You.
I guess it has to be called after the session starts. Because I am only using that once in my script I took it out of global and put it in the sub. |
#4
|
|||
|
|||
Hi Yuuichi,
I'm glad I could help. Have a great weekend.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
port forwarding , setoption |
Thread Tools | |
Display Modes | Rate This Thread |
|
|