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 11-21-2008, 07:11 PM
swsjetyn swsjetyn is offline
Registered User
 
Join Date: Jul 2008
Posts: 4
Can i get the hostname in session property?

I can't telnet some routers directly, such as routerA . So i telnet one or more proxy router first , such as Router B or (routerB & routerC) , and then telnet A from B(telnet B directly), or telnet B form C, then telnet A form B(can not telnet B directly).
And with different ip of routerA, I must select different proxy routerB or (router B &router C), maybe the same, but different probably.
This mean I canít get the remote host ip by session.RemoteAddress, because I have not connected to the RouterA.

So, the question is :
how I can get the hostname in session property. (file-->connect-->properties-->connection-->telnet-->hostname )
Reply With Quote
  #2  
Old 11-24-2008, 08:39 AM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi swsjetyn,

The session.RemoteAddress property will return the address of the machine to which SecureCRT is connected.

If I understand your explanation correctly, you are connecting via Telnet to a router, and then issue another telnet command to that router to perform a 'hop' to a different router that resides behind the original.

Is my understanding correct?

If so, can you explain more about what it is you are looking to accomplish by capturing the address of the destination router?

Also, are you issuing the secondary telnet command manually, or is your script automatically connecting to the second-level router?
Reply With Quote
  #3  
Old 11-24-2008, 06:13 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Quote:
Originally Posted by swsjetyn
I need to get the hostname in session property(file-->connect-->property-->connection-->telnet-->hostname), and then decided how to telnet to this host by one or more proxy devices.
For example, if i want to telnet deviceA, i must telnet proxyX, and then telnet proxyY from proxyX, and finally telnet deviceA from proxyY. Before i get the ip of deviceA, i can't know the ip of proxyX & proxyY. The number of proxy device need to telnet deviceA, maybe 1, or 2, or 3. This means the number of proxy is dynamic, and the ip of proxy is dynamic.
So i can't get the device's ip by session.remoteaddress. And who can tell me the way to solve this problem?
TKS!
Hi swsjetyn,

How would you be running the script?

What is it about the hostname that indicates the proxies required to establish the final connection?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #4  
Old 11-25-2008, 09:04 AM
swsjetyn swsjetyn is offline
Registered User
 
Join Date: Jul 2008
Posts: 4
my script and explanation of my question

Thanks for your reply.
Here is my script of connecting deviceX which ip is "10.0.0.151". The script runs well, i don't need to manually telnet proxyA(10.0.0.3) first, then 10.0.16.49, and finally destined devicesX(10.0.0.151), just automatically.
The key idea is that :
i set the deviceX's IP 10.0.0.151, and find that its host_uplevel_device is IP_CityASW01041, not null. This mean before i telnet destined deviceX, i must telnet IP_CityASW01041 first. And again , before i telnet IP_CityASW01041, i must telnet IP_CityASW01001 first.
Finally, i find CityASW01001 's host_uplevel_device ="", this means i can telnet CityASW01001 directly. this is just the entire analysis process. And the last actually "telnet" processing is in inverse sequence.

At the begging of this script ,i define a variable and give it a value "10.0.0.151" manually.
Dim ip_uplevel
ip_uplevel="10.0.0.151"

But now i want to telnet all devices with just one script, not one script for one device, so i must get the destined devices's ip automatically.

i think one of the way is crt.GetScriptTab.caption after i post the question. But i am afraid someone will change the session's name in "connect dialog". so i still want to know whether i can get the hostname in session property?
here i pointed out again that the session.remoteaddress won't work, because i has not connected to the device .
thanks.

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

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main
Dim ip_uplevel
ip_uplevel="10.0.16.49"


Const count_device=30
Const IP_CityASW01001="10.0.0.103"
Const IP_CityASW01041="10.0.16.49"
Const IP_CityBSW01001="10.0.0.3"
Const IP_CityBSW01041="10.0.9.11"
Dim host_name()
Dim host_ip()
Dim host_echo1()
Dim host_echo2()
Dim host_device_type()
Dim host_uplevel_device()
ReDim host_name(count_device)
ReDim host_ip(count_device)
ReDim host_echo1(count_device)
ReDim host_echo2(count_device)
ReDim host_device_type(count_device)
ReDim host_uplevel_device(count_device)

host_name(0)="_CityASW01001"
host_ip(0)="10.0.0.103"
host_echo1(0)="_CityASW01001>"
host_echo2(0)="_CityASW01001#"
host_device_type(0)="switch"
host_uplevel_device(0)=""

host_name(1)="_CityASW01002"
host_ip(1)="10.0.0.104"
host_echo1(1)="_CityASW01002>"
host_echo2(1)="_CityASW01002#"
host_device_type(1)="switch"
host_uplevel_device(1)=""

host_name(2)="_CityART01003"
host_ip(2)="10.0.0.105"
host_echo1(2)="_CityART01003>"
host_echo2(2)="_CityART01003#"
host_device_type(2)="router"
host_uplevel_device(2)=""

host_name(3)="_CityART01004"
host_ip(3)="10.0.0.106"
host_echo1(3)="_CityART01004>"
host_echo2(3)="_CityART01004#"
host_device_type(3)="router"
host_uplevel_device(3)=""

host_name(4)="_CityASW01041"
host_ip(4)="10.0.16.49"
host_echo1(4)="_CityASW01041>"
host_echo2(4)="_CityASW01041#"
host_device_type(4)="switch"
host_uplevel_device(4)=IP_CityASW01001

host_name(5)="_CityASW01042"
host_ip(5)="10.0.0.142"
host_echo1(5)="_CityASW01042>"
host_echo2(5)="_CityASW01042#"
host_device_type(5)="switch"
host_uplevel_device(5)=IP_CityASW01041

host_name(6)="_CityART01051"
host_ip(6)="10.0.0.151"
host_echo1(6)="_CityART01051>"
host_echo2(6)="_CityART01051#"
host_device_type(6)="router"
host_uplevel_device(6)=IP_CityASW01041

host_name(7)="_CityART01052"
host_ip(7)="10.0.0.152"
host_echo1(7)="_CityART01052>"
host_echo2(7)="_CityART01052#"
host_device_type(7)="router"
host_uplevel_device(7)=IP_CityASW01041

host_name(8)="_CityBSW01001"
host_ip(8)="10.0.0.3"
host_echo1(8)="_CityBSW01001>"
host_echo2(8)="_CityBSW01001#"
host_device_type(8)="switch"
host_uplevel_device(8)=""

host_name(9)="_CityBSW01002"
host_ip(9)="10.0.0.4"
host_echo1(9)="_CityBSW01002>"
host_echo2(9)="_CityBSW01002#"
host_device_type(9)="switch"
host_uplevel_device(9)=""

host_name(10)="_CityBRT01003"
host_ip(10)="10.0.0.5"
host_echo1(10)="_CityBRT01003>"
host_echo2(10)="_CityBRT01003#"
host_device_type(10)="router"
host_uplevel_device(10)=""

host_name(11)="_CityBRT01004"
host_ip(11)="10.0.0.6"
host_echo1(11)="_CityBRT01004>"
host_echo2(11)="_CityBRT01004#"
host_device_type(11)="router"
host_uplevel_device(11)=""

host_name(12)="_CityBSW01041"
host_ip(12)="10.0.9.11"
host_echo1(12)="_CityBSW01041>"
host_echo2(12)="_CityBSW01041#"
host_device_type(12)="switch"
host_uplevel_device(12)=IP_CityBSW01001

host_name(13)="_CityBSW01042"
host_ip(13)="10.0.0.42"
host_echo1(13)="_CityBSW01042>"
host_echo2(13)="_CityBSW01042#"
host_device_type(13)="switch"
host_uplevel_device(13)=IP_CityBSW01041

host_name(14)="CityCRT01051"
host_ip(14)="10.0.0.51"
host_echo1(14)="CityCRT01051>"
host_echo2(14)="CityCRT01051#"
host_device_type(14)="router"
host_uplevel_device(14)=IP_CityBSW01041

host_name(15)="CityCRT01052"
host_ip(15)="10.0.0.52"
host_echo1(15)="CityCRT01052>"
host_echo2(15)="CityCRT01052#"
host_device_type(15)="router"
host_uplevel_device(15)=""

host_name(16)="_CityDSW01001"
host_ip(16)="10.0.0.61"
host_echo1(16)="_CityDSW01001>"
host_echo2(16)="_CityDSW01001#"
host_device_type(16)="switch"
host_uplevel_device(16)=IP_CityBSW01041

host_name(17)="_CityDRT01011"
host_ip(17)="10.0.0.62"
host_echo1(17)="_CityDRT01011>"
host_echo2(17)="_CityDRT01011#"
host_device_type(17)="router"
host_uplevel_device(17)=IP_CityBSW01041

host_name(18)="_CityDRT01012"
host_ip(18)="10.0.0.63"
host_echo1(18)="_CityDRT01012>"
host_echo2(18)="_CityDRT01012#"
host_device_type(18)="router"
host_uplevel_device(18)=IP_CityBSW01041

host_name(19)="_CityESW01001"
host_ip(19)="10.0.0.201"
host_echo1(19)="_CityESW01001>"
host_echo2(19)="_CityESW01001#"
host_device_type(19)="switch"
host_uplevel_device(19)=IP_CityBSW01041

host_name(20)="_CityESW01002"
host_ip(20)="10.0.0.202"
host_echo1(20)="_CityESW01002>"
host_echo2(20)="_CityESW01002#"
host_device_type(20)="switch"
host_uplevel_device(20)=IP_CityBSW01041

host_name(21)="_CityERT01011"
host_ip(21)="10.0.0.203"
host_echo1(21)="_CityERT01011>"
host_echo2(21)="_CityERT01011#"
host_device_type(21)="router"
host_uplevel_device(21)=IP_CityBSW01041

host_name(22)="_CityERT01012"
host_ip(22)="10.0.0.204"
host_echo1(22)="_CityERT01012>"
host_echo2(22)="_CityERT01012#"
host_device_type(22)="router"
host_uplevel_device(22)=IP_CityBSW01041


Dim host_temp()
Dim i1
ReDim host_temp(count_device)
i1=-1
Do 
	i1=i1+1
	host_temp(i1)=getnumber(ip_uplevel,host_ip)
	If host_temp(i1)="wrong" Then
    MsgBox "error" & ip_uplevel
		Exit Sub 
	End If	
	ip_uplevel=host_uplevel_device(host_temp(i1))
loop until ip_uplevel=""	

For i=i1 to 0 step -1
  host_number=host_temp(i)
  If i=i1 Then
    Do While 1 
      crt.session.disconnect
    	crt.session.Connect("/telnet " & host_ip(host_number) & " 23")      
    	crt.GetScriptTab.caption="current Devices is :" & host_name(host_number)
      'log_filename=host_name(host_number) & ".txt"
      'crt.session.LogFileName=log_path & log_filename
      'If crt.session.logging =false Then
      '	crt.session.log start=false, Append=false
      'End If
  	  crt.Screen.WaitForString "Username: "
      loginID=crt.Dialog.Prompt("Enter your loginID","Logon Title","",false)
      If loginID="" Then 
         MsgBox "null username,task over"
      	 'crt.session.disconnect
      	 Exit Sub
      End If	 
  	  crt.Screen.Send loginID & chr(13)

  	  crt.Screen.WaitForString "Password:"
      login_Password = crt.Dialog.Prompt("Enter your password:", "Logon Title", "", True)
      If login_Password="" Then 
         MsgBox "null password,task over"
      	 'crt.session.disconnect
       	 Exit Sub
      End If	
  	  crt.Screen.Send login_password & chr(13)

      szResult = crt.Screen.WaitForStrings(host_echo1(host_number),"% Login invalid",2) 
  	  If szResult=1 Then
  	     Exit Do
  	  ElseIf szResult=2 Then
        crt.screen.clear
        crt.session.disconnect
  	  	MsgBox "Wrong loginID / Password." & VBCR & "Input again!"
    	  Set aa=CreateObject("scripting.filesystemobject")
        If aa.fileexists(log_path & log_filename) Then
           Call aa.DeleteFile(log_path & log_filename,true)
        End If
  	  Else
  	  	MsgBox "unknowned error"
  	  	MsgBox host_echo1(host_number) & vbcr & "_CityASW01001>"
    		crt.session.disconnect
    		Exit Sub
    	End if
  	Loop 
  Else
  	crt.Screen.Send "telnet " & host_ip(host_number) & chr(13)
  	crt.GetScriptTab.caption="current device is " & host_name(host_number)
  	crt.Screen.WaitForString "Username:"
    crt.Screen.Send loginID & chr(13)
  	crt.Screen.WaitForString "Password:"
  	crt.Screen.Send login_password & chr(13)
  	crt.Screen.WaitForString host_echo1(host_number)
  End If
Next

crt.Screen.Send "terminal length 0" & chr(13)
crt.Screen.WaitForString host_echo1(host_number)
End Sub

Function getnumber(ip_uplevel,host_ip)
flag_find=False
For i=LBound(host_ip) to UBound(host_ip)
  If host_ip(i)=ip_uplevel then
     getnumber=i
     flag_find=True
  End if
Next
If flag_find=flase Then
	getnumber="wrong"
End	If
End Function
Reply With Quote
  #5  
Old 11-25-2008, 01:16 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi swsjetyn,

The GetOption method of the SessionConfiguration Object will allow you to retrieve the host name in the session properties with our latest version of SecureCRT 6.1.0 and newer.

You can find information relating to this in the SecureCRT Help under the 'ActiveX Scripting / Script Objects Reference / SessionConfiguration Object' chapter.

For example:
szSessionOption = crt.Session.Config.GetOption("hostname")
MsgBox szSessionOption
Does this information help you to accomplish your script goal?
__________________
--Todd

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

Last edited by rtb; 11-25-2008 at 01:29 PM.
Reply With Quote
  #6  
Old 11-25-2008, 07:51 PM
swsjetyn swsjetyn is offline
Registered User
 
Join Date: Jul 2008
Posts: 4
the reason i can't find the option in help doc is version

Your reply should be work, i think.

thanks!
Reply With Quote
  #7  
Old 11-26-2008, 11:26 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi swsjetyn,

Thanks for the update.

If the suggestion I made does work, feel free to post your working script for others that might need such a solution.
__________________
--Todd

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


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 01:52 AM.