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 05-11-2013, 08:23 AM
kurtmanzano kurtmanzano is offline
Registered User
 
Join Date: May 2013
Posts: 6
simple ip textfile loop help

hi i just want to

connect telnet from line 1 of ip.txt
then common commands
disconnect

then connect telnet from line 2 of ip.txt
then common commands
disconnect


and so on and so on can some one help?

this is my code
Code:
#$language = "VBScript"
#$interface = "1.0"

crt.Screen.Synchronous = True
Const ForReading = 1

Sub Main
	' Open a file, read it in & send it one line at a time
	Dim fso, f

	Set fso = CreateObject("Scripting.FileSystemObject")

	Set f = fso.OpenTextFile("d:\ip.txt", ForReading, 1)

	Dim line, params 
	Do While f.AtEndOfStream <> True

		' Read each line of the ip file.
		'
		line = f.Readline
		crt.Session.Connect "/TELNET " & params(0) & " " & 23

		crt.Screen.WaitForString "Password: "
		crt.Screen.Send "password" & chr(13)
		crt.Screen.WaitForString "router> "
		crt.Screen.Send "exit" & chr(13)

		Set objFSO = CreateObject("Scripting.FileSystemObject")


		Const ForWriting = 2
		Const ForAppending = 8

		' Create a new file (or overwrite an existing one)
		Set objStream = objFSO.OpenTextFile( _
					"D:\MyDataFile.txt", _
					ForAppending, _
					True)

		objStream.WriteLine crt.Session.RemoteAddress
		objStream.Close
		crt.Screen.Send "exit" & chr(13)
	loop
End Sub

Last edited by miked; 05-11-2013 at 11:30 AM. Reason: put code in code block
Reply With Quote
  #2  
Old 05-11-2013, 11:33 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Greetings kurtmanzano,

I don't see any obvious problems with the code.

What happens when you run it?

If you'd like to show any screen output please send the data to support@vandyke.com, with subject line of Forum 11019.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 05-11-2013, 01:51 PM
kurtmanzano kurtmanzano is offline
Registered User
 
Join Date: May 2013
Posts: 6
working but have question

got this working

with this code

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

Sub Main
On Error Resume Next
' Open the hosts file
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileHosts = fso.OpenTextFile("d:\ip.txt", 1)
szHost = fileHosts.ReadLine
Do While len(szHost) > 4
crt.session.connect("/telnet " & szHost)
crt.Screen.Synchronous = True
crt.Screen.Send VbCr
' Commands
crt.Screen.WaitForString "Password:"
crt.Screen.Send "password1234" & chr(13)
crt.Screen.WaitForString "router> "

' START WRITING FILE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
' Create a new file (or overwrite an existing one)
Set objStream = objFSO.OpenTextFile( _
"D:\MyDataFile.txt", _
ForAppending, _
True)
objStream.WriteLine crt.Session.RemoteAddress
' END WRITING FILE
' Commands
crt.Screen.Send "exit" & chr(13)
szHost = fileHosts.ReadLine
Loop
End Sub

But i have a question is it possible since i connect from an ip list file (ip.txt) to make this multi threaded like run 1st five ips from the text file, then next five from text file? > running on tabs

thanks
Reply With Quote
  #4  
Old 05-13-2013, 11:52 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
There is no multithreaded capability with the SecureCRT scripting API. You could workaround this if you use one script to read the IP list and start SecureCRT with command-line arguments, including the hostname or IP to connect to, /T to open in a tab, and the script to run. If you wanted to limit the number of simultaneous open connections to like five, the calling script would need to manage the connections. This would be a complicated solution.

I've added your forum post to our request database so that we can follow up in this thread if it becomes possible in a future release. Let us know and refer to forum thread 11019 if you'd like to be notified via e-mail as well.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
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 02:56 PM.