View Single Post
  #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