need help with TelnetDLX - WeOnlyDo Discussion board

need help with TelnetDLX (wodSSH / wodSSH.NET)

by Kevin Hall, Monday, June 22, 2009, 18:07 (5634 days ago)

I need help looping through a list of servers. I need to connect to server 1 send commands disconct. Server 2 send commands disconnect etc. I can get it to work using the 2. Using Prompt property vb6 example but I don't know how to due the loop. Can someone help me using that example or provide a vbs example using the Telnet1_PromptReceived.

Thanks

Re: need help with TelnetDLX

by woddrazen, Monday, June 22, 2009, 18:56 (5634 days ago) @ Kevin Hall

Hi Kevin,


VBscript is scripting environment so Events will now work there.

Here is VBS example that will connect to multiple servers using wodTelnetDLX and blocking mode.
[code]Dim tel1, mcol, servColl, server_hostname, server_login, server_password, first, second, serverNum
Set tel1 = WScript.CreateObject( WeOnlyDo.wodTelnetDLXCom.1 )
Set mcol = WScript.CreateObject( Scripting.Dictionary )

mcol.add 1, server1_hostname/server1_login/server1_password
mcol.add 2, server2_hostname/server2_login/server2_password
mcol.add 3, server3_hostname/server3_login/server3_password
mcol.add 4, server4_hostname/server4_login/server4_password
' and so on ...

serverNum = 0
Do
serverNum = serverNum + 1

servColl = mcol.item(serverNum)
first = InStr(1, servColl, / )
Second = InStr(first + 1, servColl, / )
server_hostname = Left(servColl, first - 1)
server_login = Mid(servColl, first + 1, Second - first - 1)
server_password = Right(servColl, Len(servColl) - second)

tel1.Timeout = 10
tel1.Protocol = 3
tel1.Blocking = 1
tel1.HostName = server_hostname
tel1.Login = server_login
tel1.Password = server_password
tel1.Connect

tel1.WaitFor ( regex:[$ #>] $ )
tel1.DataReady = 0
Wscript.Echo(tel1.Execute( ls -al + vbLf, regex:[$ #>] $ ))
tel1.Disconnect
Loop Until serverNum = mcol.Count

Wscript.Echo Done
[/code]
Hope this helps.


Regards,
Drazen

Re: need help with TelnetDLX

by Kevin Hall, Monday, June 22, 2009, 19:51 (5634 days ago) @ woddrazen

Thats exactly what I need but how do I switch prompts... When you send a new user su

Option Explicit
Dim tel1, mcol, servColl, server_hostname, server_login, server_password, first, second, serverNum, mExecuted
Set tel1 = WScript.CreateObject( WeOnlyDo.wodTelnetDLXCom.1 )
Set mcol = WScript.CreateObject( Scripting.Dictionary )

mcol.add 1, someserver/usera/

serverNum = 0
Do
serverNum = serverNum + 1

servColl = mcol.item(serverNum)
first = InStr(1, servColl, / )
Second = InStr(first + 1, servColl, / )
server_hostname = Left(servColl, first - 1)
server_login = Mid(servColl, first + 1, Second - first - 1)
server_password = Right(servColl, Len(servColl) - second)

tel1.Timeout = 100
tel1.Protocol = 1
tel1.Blocking = 1
tel1.Port = 23
tel1.HostName = server_hostname
tel1.Login = server_login
tel1.Password = vbNullString
tel1.Connect

tel1.WaitFor ( regex:[$ #>:] $ )
tel1.DataReady = 0

mExecuted = tel1.Execute( cat /usr/spool/output/reportprnt/status + vbLf, regex:[$ #>:] $ )
WScript.Echo mExecuted

'When the queue is good it will says sending to REPORTPRNT
If InStr(1, mExecuted , sending to REPORTPRNT ) Then
Else

mExecuted = tel1.Execute( cd /usr/spool/output/reportprnt/ + vbLf, regex:[$ #>] $ )
WScript.Echo mExecuted

'######## HOW DO I SWITCH PROMPTS HERE TO WAIT FOR THE password:
'tel1.WaitFor ( regex:[$ #>:] : )
mExecuted = tel1.Execute( su + vbLf, regex:[$ #>:] : )
WScript.Echo mExecuted

mExecuted = tel1.Execute( suPassord + vbLf, regex:[$ #>] passowrd: )
WScript.Echo mExecuted [code][/code]

Re: need help with TelnetDLX

by woddrazen, Monday, June 22, 2009, 23:41 (5634 days ago) @ Kevin Hall

Kevin,


Please try this:[code]mExecuted = tel1.Execute( su + vbLf, password: )[/code]
regex:[/$ #>] it actually regular expression which is used to accept many UNIX prompts.

You can use always direct prompt value if you know which next prompt you will receive from your server. So please remove regex value from Execute line and try with password:

More help for Execute Method you can find here:
http://www.weonlydo.com/TelnetDLX/Help/WODTELNETDLXLIB~wodTelnetDLX~Execute.html

Let us know how it goes.


Drazen