当前位置:网站首页>Use the securecrtportable script function to read data from network devices

Use the securecrtportable script function to read data from network devices

2022-06-11 22:09:00 dawn

   Always use SecureCRTPortable To maintain network devices .

   There are too many network commands , I find the work tedious and boring , One of the daily tasks is to frequently read the data records of network devices from network devices , Previously used Python Script to complete , It's very convenient , It is not used again Python, To use now, you must install Python, Don't want to toss .

   Come across SecureCRTPortable With script recording function , Check on the Internet , It can execute scripts , Include VBScript、JavaScript and Python, It's so good !

   I checked the relevant information this afternoon , utilize VBScript Completed the previous use Python Finished function .

   The script is as follows :

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

crt.Screen.Synchronous = True
crt. Window.show 0
'crt.Window.State 0

Sub Main
	dim NetEquipmentName
	dim NetEquipmentIP
	dim UserName
	dim UserPwd
	dim LogFileName
	dim LogPath
	' Set parameters 
	NetEquipmentName=" Network device name "
	NetEquipmentIP="IP Address "
	UserName=" user name "
	Userpwd=" password "
	LogPath=" File path "
	LogFileName=LogPath & NetEquipmentName & Year(Now) & Month(Now) & Day(Now) & "-" & Hour(Now) & Minute(Now) & ".txt"
	' Access network devices 
	crt.session.Connect("/telnet " & NetEquipmentIP )
	'crt.Window.Activate
	'crt. Window.show 0
	'crt.Window.State=0
	crt.Screen.WaitForString("ogin:")
	crt.Screen.Send(UserName & chr(13))
	crt.Screen.WaitForString("assword:")
	crt.Screen.Send(UserPwd & chr(13))
	crt.Screen.WaitForString("<xxs01>")
	crt.Session.LogFileName=LogFileName
	crt.Session.Log True
	crt.Screen.Send " command   " & chr(13)
	Do while crt.Screen.WaitForString("---- More ----",1,true)=True
		crt.Sleep(500)
		crt.Screen.Send " " & chr(13)
	Loop
	crt.Screen.Send "quit"	& chr(13)
	crt.Session.Disconnect()

	' Exit procedure 
	crt.Screen.Synchronous = False
	crt.quit()
End Sub

   Write a bat file , There's only one line :

 File path \SecureCRT.exe   /SCRIPT DailyNetworkDataCollection.vbs

   stay windows Add this to your plan list bat File can be installed for a fixed time .

   This function is really practical ! A lot of work has been reduced !

原网站

版权声明
本文为[dawn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206112148572907.html