1

我已将代码设置为 telnet 进入交换机并将启动配置 tftp 到服务器。如果我将 IP 地址硬编码到脚本中,则此代码可以完美运行。

我想做的是将IP地址列表(一个接一个)传递给脚本,以便我可以复制网络上的所有交换机配置。我在下面包含了一些代码,这是我用来创建脚本的代码。我想要做的就是用 IP 地址列表替换“telnet xx.xx.xx.xx”xx.xx.xx.xx 条目。

提前致谢!

这是我使用的代码副本:

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 xx.xx.xx.xx"

WshShell.SendKeys ("{Enter}")

WScript.Sleep 1000

'Step 2 - Issue Commands with pauses'

WshShell.SendKeys ("{Enter}")

WScript.Sleep 1000

WshShell.SendKeys "5"

WshShell.SendKeys ("{Enter}")

WScript.Sleep 1000

'Step 3 - Exit Command Window

WshShell.SendKeys "exit"

WshShell.SendKeys ("{Enter}")

WScript.Quit 
4

1 回答 1

1

试试这个,主要是你的代码,只插入几行以循环遍历纯文本格式的 IP 地址列表。请让我知道这是否适合您。这样做会为每个 telnet 主机打开一个新的命令窗口,然后在完成后将其关闭。修改为使用相同的命令窗口可能很容易。

Option Explicit

On Error Resume Next

Dim WshShell
Dim objFSO
Dim objInputFile
Dim strIP

set WshShell=CreateObject("WScript.Shell")


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objInputFile = objFSO.OpenTextFile("IPFilelist.txt", 1)

Do Until objInputFile.AtEndofStream

    strIP = objInputFile.ReadLine

    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 " & strIP

    WshShell.SendKeys ("{Enter}")

    WScript.Sleep 1000

    'Step 2 - Issue Commands with pauses'

    WshShell.SendKeys ("{Enter}")

    WScript.Sleep 1000

    WshShell.SendKeys "5"

    WshShell.SendKeys ("{Enter}")

    WScript.Sleep 1000

    'Step 3 - Exit Command Window

    WshShell.SendKeys "exit"

    WshShell.SendKeys ("{Enter}")

Loop

WScript.Quit 
于 2013-02-25T21:45:56.880 回答