2016-08-29 1 views
-1

J'ai de nombreux commutateurs que nous sauvegardons tous les soirs. J'ai besoin de créer un travail qui sauvegardera automatiquement la configuration en cours.Commutateurs automatiques Telnet vers Cisco

Je l'utilise actuellement, mais comment puis-je utiliser une liste d'adresses IP du serveur au lieu d'avoir à répéter le code.

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}") 
+0

bien qu'il soit évident que c'est une sorte de script Visual Basic, il aide vraiment obtenir le bon public pour votre question si vous étiquetez correctement à la question avec des balises linguistiques, et/ou des balises d'environnement aussi bien. S'il vous plaît modifier votre question pour mettre à jour vos tags.S'il vous plaît également [lire sur la façon de poser de bonnes questions] (http://stackoverflow.com/help/how-to-ask) –

+0

Je vois des adresses IP dans 3 sp ots dans le script. Je vois que le premier est l'IP telnet pour le routeur cible. À quoi servent les 2 autres? Est-ce que ceux-ci changent ou restent-ils les mêmes? Besoin de savoir ceci avant qu'une boucle puisse être installée. –

+0

Salut, Merci pour vos réponses. Désolé si je n'ai pas utilisé le bon tag Je suis nouveau sur ce forum. C'est la seule ip qui va changer WshShell.SendKeys "telnet 10.1.130.91 23" adresses ip sont: 10.10.130.91, 10.1.130.101 et ainsi de suite Appréciez votre aide :-) –

Répondre

0

Vous continuez ici. Il suffit de créer un fichier nommé CiscoIPs.txt avec toute votre adresse IP avec un retour chariot après chacun d'eux. Évitez les espaces à la fin des enregistrements.

10.2.2.23 
10.4.5.23 
10.5.7.23 

La liste IP doit être dans le même dossier que le VBScript, mais vous pouvez certainement changer en éditant « strIPFile = « CiscoIPs.txt » en haut du script. Faites-moi savoir si vous avez questions.

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 
+0

Lars, j'ai oublié de mentionner. Si jamais vous avez besoin de créer un script Telnet à partir de zéro, cet utilitaire est le meilleur que j'ai vu. "Telnet Scripting Tool" Consultez ma réponse sur cet article. http://stackoverflow.com/questions/39274914/how-to-write-an-output-of-a-vb-script-to-a-file/39280318#39280318 –