自动Telnet到cisco交换机
Automatic Telnet to cisco switches
我有很多交换机,我们每晚都会备份。我需要创建一个自动备份 运行 配置的作业。
我目前正在使用它,但我怎样才能使用服务器 IP 地址列表而不是重复代码。
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet 10.1.130.91 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("password")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("Enable")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("password")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("terminal length 0")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("show running-config")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("copy run tftp://10.1.211.53/file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("10.1.211.53")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 2000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
给你。只需创建一个名为 CiscoIPs.txt 的文件,其中包含您所有的 IP 地址,并在每个 IP 地址后添加一个回车符 return。避免记录末尾有空格。
10.2.2.23
10.4.5.23
10.5.7.23
IP 列表应与 VBScript 位于同一文件夹中,但您当然可以通过编辑脚本顶部的 "strIPFile = "CiscoIPs.txt" 来更改它。如果您有,请告诉我任何问题。
Option Explicit
Dim WshShell, strIPFile, objFSO, objFile, IPAddress
strIPFile = "CiscoIPs.txt"
On Error Resume Next
set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const ReadOnly = 1
Set objFile = objFSO.OpenTextFile(strIPFile, ForReading)
Do Until objFile.AtEndOfStream
IPAddress = objFile.ReadLine
'WScript.Echo IPAddress
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet " & IPAddress & " 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("password")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("Enable")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("password")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("terminal length 0")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("show running-config")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("copy run tftp://" & IPAddress & ".xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("10.1.211.53")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 2000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
Loop
objFile.Close
我有很多交换机,我们每晚都会备份。我需要创建一个自动备份 运行 配置的作业。
我目前正在使用它,但我怎样才能使用服务器 IP 地址列表而不是重复代码。
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet 10.1.130.91 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("password")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("Enable")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("password")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("terminal length 0")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("show running-config")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("copy run tftp://10.1.211.53/file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("10.1.211.53")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 2000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
给你。只需创建一个名为 CiscoIPs.txt 的文件,其中包含您所有的 IP 地址,并在每个 IP 地址后添加一个回车符 return。避免记录末尾有空格。
10.2.2.23
10.4.5.23
10.5.7.23
IP 列表应与 VBScript 位于同一文件夹中,但您当然可以通过编辑脚本顶部的 "strIPFile = "CiscoIPs.txt" 来更改它。如果您有,请告诉我任何问题。
Option Explicit
Dim WshShell, strIPFile, objFSO, objFile, IPAddress
strIPFile = "CiscoIPs.txt"
On Error Resume Next
set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const ReadOnly = 1
Set objFile = objFSO.OpenTextFile(strIPFile, ForReading)
Do Until objFile.AtEndOfStream
IPAddress = objFile.ReadLine
'WScript.Echo IPAddress
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet " & IPAddress & " 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("password")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("Enable")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("password")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("terminal length 0")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("show running-config")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("copy run tftp://" & IPAddress & ".xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("10.1.211.53")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 2000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
Loop
objFile.Close