1

スイッチに telnet で接続し、startup-config をサーバーに tftp するようにコードをセットアップしました。このコードは、IP アドレスをスクリプトにハード コードすると完璧に機能します。

私がやりたいことは、ネットワーク上のすべてのスイッチ構成をコピーできるように、IP アドレスのリストを (次々に) スクリプトに渡すことです。以下にいくつかのコードを含めました。これは、スクリプトの作成に使用したコードです。私ができるようにしたいのは、「telnet xx.xx.xx.xx」xx.xx.xx.xx エントリを 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 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 に答える