VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Get session ip addres (https://forums.vandyke.com/showthread.php?t=10903)

sind 02-24-2013 01:43 AM

Get session ip addres
 
Hi!

How can i get ip address of the session?

I need to do is something like:

If Session IP is "192.168." Then
MsgBox "Ok"
Else
MsgBox "Bad"
End If

rtb 02-25-2013 07:27 AM

Hi sind,

Thanks for the question. If you are connected to the session you could use the RemoteAddress property of the Session object.

Would this work for you?

If not, can you provide more specific details about your goal?

sind 02-25-2013 07:47 AM

I have a devices of different vendors in the different subnets. And I want to connect them with a script.

Login prompt they have the same. So I want to identify them at the session IP.

Example:


Code:

If Session IP is "192.168." Then
    crt.Screen.WaitForString "Login:"
    objTab.Screen.Send login1 & vbcr
    crt.Screen.WaitForString "Password:"
    objTab.Screen.Send password1 & vbcr
Else If Session IP is "10.0." Then
    crt.Screen.WaitForString "Login:"
    objTab.Screen.Send login2 & vbcr
    crt.Screen.WaitForString "Password:"
    objTab.Screen.Send password2 & vbcr
End If


rtb 02-25-2013 09:47 AM

Hi sind,

How are you going to be running this script?

How does the script know what session is being used to connect?

sind 02-25-2013 10:46 AM

This script is set to the default session in program. I type IP address to connect bar and script starting.

rtb 02-25-2013 11:37 AM

Hello sind,

Thanks for the information. This sounds like it might be useful for other users, so here is an example:
Code:

' Get handle to ad hoc session in tab created by script
Set objTab = crt.GetScriptTab
' Get handle to the configuration for the session
Set objConfig = crt.Session.Config
' Take action depending on the IP address of the session
If InStr(objConfig.GetOption("Hostname"), "192.168") Then
    objTab.Screen.Synchronous = True
    objTab.Screen.Send "user1" & vbcr
    objTab.Screen.WaitForString "word:"
    objTab.Screen.Send "pass1" & vbcr
Else
    objTab.Screen.Synchronous = True
    objTab.Screen.Send "user2" & vbcr
    objTab.Screen.WaitForString "word:"
    objTab.Screen.Send "pass2" & vbcr
End If

Notice that you are using the SessionConfiguration object. Information about this object and associated properties is in the Scripting / Script Objects Reference / SessionConfiguration Object chapter.

Does this help you accomplish your goal?

sind 02-25-2013 12:13 PM

Thanks. Works fine.

rtb 02-25-2013 01:24 PM

Hi sind,

Thanks for the confirmation. For those that see this and want to use it, it is necessary to define the script as a Logon script: in the Default Session. It is also necessary to enable Display logon prompts in terminal window.

You can edit the Default Session by pressing the Edit Default Settings... button in the General / Default Session category of the Global Options dialog. Once you see the following dialog, select Change Default session only:
---------------------------
Apply default session changes
---------------------------
Do you want to apply the changes that you made to the Default Session or to ALL of your sessions?



WARNING: There is no UNDO for this change.


---------------------------
Change Default session only Change ALL sessions (no undo)
---------------------------


All times are GMT -6. The time now is 02:26 PM.