我是靠谱客的博主 凶狠高跟鞋,最近开发中收集的这篇文章主要介绍利用SecureCRTPortable脚本功能完成网络设备的数据读取,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  一直使用SecureCRTPortable来维护网络设备。

  敲网络命令多了,觉得这工作繁琐枯燥,日常的工作之一就是频繁从网络设备中读取网络设备的数据记录,先前使用Python脚本来完成,挺方便,后面也没有再使用Python,现在要使用则必须安装Python,不想折腾了。

  无意中看到SecureCRTPortable有录制脚本功能,上网一查,它可以执行脚本,包括VBScript、JavaScript和Python,实在是太好了!

  今天下午查了相关资料,利用VBScript完成了先前使用Python完成的功能。

  脚本如下:

#$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
	'设置参数
	NetEquipmentName="网络设备名称"
	NetEquipmentIP="IP地址"
	UserName="用户名"
	Userpwd="密码"
	LogPath="文件路径"
	LogFileName=LogPath & NetEquipmentName & Year(Now) & Month(Now) & Day(Now) & "-" & Hour(Now) & Minute(Now) & ".txt"
	'访问网络设备
	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 "命令  " & 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()

	'退出程序
	crt.Screen.Synchronous = False
	crt.quit()
End Sub

  上面列出的是telnet,现在很多网络设备需要SSH2登录,对应的登录需要替换:

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

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

Sub Main
	dim NetEquipmentName
	dim NetEquipmentIP
	dim UserName
	dim UserPwd
	dim LogFileName
	dim LogPath
	'设置参数
	NetEquipmentName="设备名称"
	NetEquipmentIP="IP地址"
	UserName="用户名称"
	Userpwd="用户密码"
	LogPath="存储路径"
	LogFileName=LogPath & NetEquipmentName & Year(Now) & Month(Now) & Day(Now) & "-" & Hour(Now) & Minute(Now) & ".txt"
	'访问交换机或者路由器
	crt.Session.Connect "/SSH2 /ACCEPTHOSTKEYS /L " & UserName & " /PASSWORD " & Userpwd & " /C 3DES /M SHA1 " & NetEquipmentIP  	
	crt.Screen.WaitForString("<" & NetEquipmentName &">")
	crt.Session.LogFileName=LogFileName
	crt.Session.Log True
	crt.Screen.Send "dis arp" & 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()

	'退出程序
	crt.Screen.Synchronous = False
	crt.quit()
End Sub

  写一个bat文件,内容只有一行:

文件路径SecureCRT.exe   /SCRIPT DailyNetworkDataCollection.vbs

  在windows的计划列表里添加这个bat文件即可安装固定的时间执行了。

  这里可以做一个脚本来判断,后面做一个完整的。

  这个功能是真的实用啊!减轻了不少的工作量了!

最后

以上就是凶狠高跟鞋为你收集整理的利用SecureCRTPortable脚本功能完成网络设备的数据读取的全部内容,希望文章能够帮你解决利用SecureCRTPortable脚本功能完成网络设备的数据读取所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部