Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-09-2017, 11:03 AM
Yuuichi Yuuichi is offline
Registered User
 
Join Date: Jun 2017
Posts: 2
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
Reply With Quote
  #2  
Old 06-09-2017, 01:05 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
  #3  
Old 06-09-2017, 02:43 PM
Yuuichi Yuuichi is offline
Registered User
 
Join Date: Jun 2017
Posts: 2
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.
Reply With Quote
  #4  
Old 06-09-2017, 04:02 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Yuuichi,

I'm glad I could help.

Have a great weekend.
__________________
Thanks,
--Eric

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

Tags
port forwarding , setoption


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 04:24 PM.