How to implement Telnet login with batch processing and make some simple commands

Source: Internet
Author: User


Example 1:

The following commands are specified:
Log in to 192.168.1.100 first.
Telnet 192.168.0.100
Username:aaa
password:111
Do a few simple pings after landing
Ping 192.168.0.1
Ping 192.168.0.2
How to use the batch processing of CMD how to achieve.

Back to the first floor, certainly can, I want to log on is a route, I see someone has done a feasible.

Save the following code as a batch processing (*.bat) rem =========yobo-lily copyright ======= @del c:\temp.vbs @echo On Error Resume Next >>c:\temp.vbs @echo Dim wshshell>>c:\temp.vbs @echo Set WshShell = WScript.CreateObject ("Wscript.Shell") >>c:\temp.vbs @echo Wshshell.run "cmd" >>c:\temp.vbs @echo wshshell.appactivate "C:\windows\system32\cmd.exe" >>c:\temp.vbs @ echo wscript.sleep 200>>c:\temp.vbs @echo Wshshell.sendkeys "telnet 192.168.1.100" >>c:\temp.vbs @echo Wshshell.sendkeys ' {ENTER} ' >>c:\temp.vbs @echo wscript.sleep 100>>c:\temp.vbs @echo wshshell.appactivate "Telnet.exe" >>c:\temp.vbs @echo wscript.sleep 2000>>c:\temp.vbs @echo Wshshell.sendkeys "AAA" >>c:\ Temp.vbs @echo Wshshell.sendkeys "{ENTER}" >>c:\temp.vbs @echo wscript.sleep 2000>>c:\temp.vbs @echo Wshshell.sendkeys ">>c:\temp.vbs" @echo Wshshell.sendkeys "{ENTER}" >>c:\temp.vbs @echo Wscript.Sleep 2000>>c:\temp.vbs @echo Wshshell.sendkeys "Ping 192.168.0.1" >>c:\tempThe. vbs @echo Wshshell.sendkeys "{ENTER}" >>c:\temp.vbs @echo wscript.sleep 1000>>c:\temp.vbs @echo Wshshell.sendkeys "Ping 192.168.0.2" >>c:\temp.vbs @echo Wshshell.sendkeys "{ENTER}" >>c:\temp.vbs @echo Wscript.Sleep 1000>>c:\temp.vbs @call c:\temp.vbs rem =========yobo-lily copyright =======

Example 2:

Windows platform:
Copy the code to Notepad and save it as Autotelnet.bat, and then double-click to run to achieve automatic login to Telnet server, the server IP itself modified
@echo off
Echo setsh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "Open 192.168.1.200" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys ' {ENTER} ' >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "login account {ENTER}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "Login Password {ENTER}" >>telnet_tmp.vbs
Start Telnet
cscript. Nologo Telnet_tmp.vbs
Del Telnet_tmp.vbs

Example 3:

Because of the implementation of network engineering, it is necessary to configure a large number of devices, and at the end of the project to configure a large number of equipment backup.
So want to do a batch tool automatically telnet. At present, combined with the results of Baidu Search, has completed the following functions:, 1, through the BAT file automatically generated VBS file 2, after running the VBS file, automatic Telnet device, and enter the ready command.

You can configure, or you can back up the configuration. Code as follows: 1, BAT file code: @del. \temp.vbs @echo On Error Resume Next >>.\temp.vbs @echo Dim wshshell>>.\temp.vbs @e 
Cho Set WshShell = WScript.CreateObject ("Wscript.Shell") >>.\temp.vbs @echo wshshell.run "cmd" >>.\temp.vbs 
@echo wshshell.appactivate ". \windows\system32\cmd.exe" >>.\temp.vbs @echo wscript.sleep 200>>.\temp.vbs @echo Wshshell.sendkeys "Telnet 192.168.1.2" >>.\temp.vbs @echo Wshshell.sendkeys "{ENTER}" >>.\temp.vbs @ echo wscript.sleep 100>>.\temp.vbs @echo wshshell.appactivate "Telnet.exe" >>.\temp.vbs @echo Wscript.Sleep 1000>>.\temp.vbs for/f "Tokens=1 delims="%%a in (' type. \input.txt ') do (@echo Wshshell.sendkeys "%) A ">>.\temp.vbs" & (@echo Wshshell.sendkeys "{ENTER}" >>.\temp.vbs) & (@echo Wscript.Sleep 1000> >.\temp.vbs) @call. \ tEmp.vbs>>.\temp1.txt 2, code for the generated VBS: On Error Resume next  Dim WshShell Set WshShell = WScript.CreateObject ("WS Cript. Shell "Wshshell.run" cmd "wshshell.appactivate". \windows\system32\cmd.exe "Wscript.Sleep Wshshell.sendkeys" 
Telnet 192.168.1.2 "Wshshell.sendkeys" {ENTER} "Wscript.Sleep wshshell.appactivate" Telnet.exe "Wscript.Sleep 1000 Wshshell.sendkeys "Cisco" Wshshell.sendkeys "{ENTER}" Wscript.Sleep 1000 Wshshell.sendkeys "en" Wshshell.sendkeys "{ ENTER} "Wscript.Sleep 1000 Wshshell.sendkeys" Cisco Wshshell.sendkeys "{ENTER}" Wscript.Sleep 1000 Wshshell.sendkeys show ip int br "Wshshell.sendkeys" {Enter} "Wscript.Sleep 1000 Wshshell.sendkeys" conf T "Wshshell.sendkeys" {Enter} "Wscri Pt. 
Sleep 1000 Wshshell.sendkeys "exit" Wshshell.sendkeys "{ENTER}" Wscript.Sleep 1000 Wshshell.sendkeys "Exit" Wshshell.sendkeys "{ENTER}" Wscript.Sleep 1000 3, I tested TXT text cisco en show ip int br conf t exit exit when used, just want txt text

Drag to the icon on the bat file. Legacy issues: 1, the generated VBS code, a command output can not be based on the networkThe command result returned by the device is configured next, but the wait time for the sleep is the next step. This is not compatible with certain commands that need to be executed for a long time.
It's better to have a method like waitforstring or experts, wait for the result to be returned and enter the next command. 2, the existing VBS code, cannot record the entire batch process execution. Only after the end, through TFTP to test the configuration file. Inconvenient, also not at ease.

Example 4:

Because of the implementation of network engineering, it is necessary to configure a large number of devices, and at the end of the project to configure a large number of equipment backup. So want to do a batch tool automatically telnet.
At present, combined with the results of Baidu Search, has completed the following functions:,
1. Automatically generate VBS file through BAT file
2, after running the VBS file, automatic Telnet device, and enter the prepared command. You can configure, or you can back up the configuration.

The code is as follows:
1, BAT file code:

@del. \temp.vbs

@echoon Error Resume Next >>.\temp.vbs

@echodim Wshshell>>.\temp.vbs

@echoSet WshShell = WScript.CreateObject ("Wscript.Shell") >>.\temp.vbs

@echoWshShell. Run "cmd" >>.\temp.vbs

@echoWshShell. AppActivate ". \windows\system32\cmd.exe" >>.\temp.vbs

@echoWScript. Sleep 200>>.\temp.vbs

@echoWshShell. SendKeys "Telnet 192.168.1.2" >>.\temp.vbs

@echoWshShell. SendKeys "{ENTER}" >>.\temp.vbs

@echoWScript. Sleep 100>>.\temp.vbs

@echoWshShell. AppActivate "Telnet.exe" >>.\temp.vbs

@echoWScript. Sleep 1000>>.\temp.vbs

for/f "Tokens=1 delims="%%a in (' type. \input.txt ') do (@echoWshShell. SendKeys "%%a" >>.\temp.vbs) & (@ Echowshshell.sendkeys ' {ENTER} ' >>.\temp.vbs & (@echoWScript. Sleep 1000>>.\temp.vbs)

@call. \temp.vbs>>.\temp1.txt

2. Code of the generated VBS:

On Error Resume Next

Dim WshShell

Set WshShell =wscript.createobject ("Wscript.Shell")

Wshshell.run "cmd"

Wshshell.appactivate ". \windows\system32\cmd.exe"

Wscript.Sleep 200

Wshshell.sendkeys "Telnet 192.168.1.2"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 100

Wshshell.appactivate "Telnet.exe"

Wscript.Sleep 1000

Wshshell.sendkeys "Cisco"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 1000

Wshshell.sendkeys "en"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 1000

Wshshell.sendkeys "Cisco"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 1000

Wshshell.sendkeys "show ip int br"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 1000

Wshshell.sendkeys "conf T"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 1000

Wshshell.sendkeys "Exit"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 1000

Wshshell.sendkeys "Exit"

Wshshell.sendkeys ' {ENTER} '

Wscript.Sleep 1000

3, I test the txt text

Cisco

En

Cisco

show IP int BR

Conf t

Exit

Exit

When you use it, just drag the txt text to the icon on the bat file.



Legacy issues:
1, the generated VBS code, a command output can not be returned according to the network device command results of the next configuration, but through the waiting time for sleep to the next configuration. This is not compatible with certain commands that need to be executed for a long time. It's better to have a method like waitforstring or experts, wait for the result to be returned and enter the next command.
2, the existing VBS code, cannot record the entire batch process execution. Only after the end, through TFTP to test the configuration file. Inconvenient, also not at ease.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.