Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Thread Tools Rate Thread Display Modes
Old 03-01-2014, 11:24 PM
kumar kumar is offline
Registered User
Join Date: Mar 2014
Posts: 1
problem - telnet device one after other

i have attached the sample script and csv file.

I have an csv file which contains all the list of devices with IP Address and Credentials. I need to login to each device one by one and read the hostname and IOS version and write that to csv.

I have attached my sample code. i am able to telnet and login to first device and then able to write the host name to file but could not login to other devices which i am running in a LOOP.

Error: Connect: already connected

Excel file:

Sub Main()

Dim nRowIndex, n

Set objApp = CreateObject("Excel.Application")
Set objWbs = objApp.Workbooks
objApp.Visible = True
Set objWorkbook = objWbs.Open("c:\temp\sample.xlsx")
Set objSheet = objWorkbook.Sheets("Sheet1")

'Convert Letter column indicators to numerical references
nIPAddr = Asc("A") - 64
nusrname = Asc("B") - 64
nusrpswd = Asc("C") - 64
nenable = Asc("D") - 64
nhostname = Asc("E") - 64
nIOS = Asc("F") - 64
nstatus = Asc("G") - 64
nRowIndex = 2
n = 5


'Read IP Address from Excel
IPAddr = Trim(objSheet.Cells(nRowIndex, nIPAddr).Value)
'If IPAddr = "" Then Exit Do
crt.Screen.Synchronous = True
'Read Username from Excel
usrname = Trim(objSheet.Cells(nRowIndex, nusrname).Value)
'If usrname = "" Then Exit Do
crt.Screen.Synchronous = True
'Read User Password from Excel
usrpswd = Trim(objSheet.Cells(nRowIndex, nusrpswd).Value)
'If usrpswd = "" Then Exit Do
crt.Screen.Synchronous = True
'Read Enable Password from Excel
'enable = Trim(objSheet.Cells(nRowIndex, nenable).Value)
'If enable = "" Then Exit Do
'crt.Screen.Synchronous = True
'connect to host on port 23 (the default telnet port)
crt.Session.Connect ("/TELNET " & IPAddr & " " & "23")
On Error Resume Next

'Log the Success message in the spreadsheet
If crt.Session.Connected Then objSheet.Cells(nRowIndex, nstatus).Value = "Success"
If Not crt.Session.Connected Then objSheet.Cells(nRowIndex, nstatus).Value = Err.Description
'If Not crt.Session.Connected Then Exit Do

'login name
crt.Screen.WaitForString "username: "
crt.Screen.Send usrname & vbCr
'login Password
crt.Screen.WaitForString "password:"
crt.Screen.Send usrpswd & vbCr
'Enable password
crt.Screen.WaitForString "#"
crt.Screen.Send "enable" & vbCr
crt.Screen.WaitForString "Password:"
crt.Screen.Send Enable & vbCr
'Get Hostname
crt.Screen.WaitForString "#"
crt.Screen.Send vbCr
crt.Screen.WaitForString vbCr
crt.Screen.WaitForString vbLf
hostname = crt.Screen.ReadString("#")
'crt.Screen.Send "exit" & vbcr
'crt.Screen.Send vbCr
objSheet.Cells(nRowIndex, nhostname).Value = hostname
'Disconnect Session
crt.Screen.Send vbCr
crt.Screen.WaitForString "#"
crt.Screen.Synchronous = False
'move down to the next row in the spreadsheet
nRowIndex = nRowIndex + 1
Loop while nRowIndex < n


MsgBox "Done"

End Sub


Please some one help me to fix this
Reply With Quote
Old 03-03-2014, 09:48 AM
rtb rtb is offline
VanDyke Technical Support
Join Date: Aug 2008
Posts: 4,305
Hi Kumar,

Thanks for the post.

It would appear based on the error that the previous connection has not yet disconnected.

You may consider disconnecting, and then waiting in a loop to ensure you are disconnected prior to trying to connect again. The property you need is Connected, and it is a part of the Session object.

Does this help resolve the issue?

VanDyke Software
Technical Support
Reply With Quote

telnet multiple devices , telnet script

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 10:01 PM.