BAT for telnet access passing user and password

Asked

Viewed 2,751 times

3

inserir a descrição da imagem aqui

How to use a bat to access a host via telnet to automate backup.

I tried to call the telnet, but. how to pass the user and password and be recognised.

It only opens the prompt of telnet and ask me to log in.

I’m using these commands:

telnet 10.0.50.1
local-user=mardencmt
password=admin
ECHO %local-user%
ECHO %password%
  • Vinicius, by which I know it is only possible to specify the user previously, no?

  • 1

    As follows: telnet [-a][-e escape char][-f log file][-l user][-t term][host]]

  • I honestly don’t know Fabricio, rsrsrs. First time I had to do this...

1 answer

4

----

The telnet command offers no options for insertion of dice of login:


inserir a descrição da imagem aqui

I’ll leave two here possible options to do it via bat/cmd with /VBS & bat/cmd with Telnet Script Tool:

One option would be Sendkey (VBS) very useful for send data simulating a typing and sending the data to the telnet login

Below is an example of the use of SendKey (VBS) to send input data



1) Example in a bat that generates in running time one VBS for effect that one task.

Only replace on the lines below the respective values to the variables:

[user] [password] [cmd]

set "user=mardencmt" & set "password=admin"

set "cmd=telnet 10.0.50.1"


inserir a descrição da imagem aqui


@echo off & setlocal enabledelayedexpansion & cls

echo/ & mode con cols=77 lines=30& color 9F

set "_usuario_=cisco_user" & set "_senha_=4LoCk007XSwT001"
set "_cmd_=telnet.exe 192.168.0.254"

>"%temp%\_temp_file_4vbs_.vbs"^
    (
     echo/ Set WshShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ Set objShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ StrPwd  = "!_senha_!"
     echo/ StrUser = "!_usuario_!"
     echo/ for i=1 To Len^(StrUser^)
     echo/     x = Mid^(StrUser,i,1^)
     echo/     WshShell.SendKeys x
     echo/     Wscript.Sleep 250
     echo/ Next
     echo/ Wscript.Sleep 500
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ for j=1 To Len^(StrPwd^)
     echo/     x = Mid^(StrPwd,j,1^)
     echo/     WshShell.SendKeys x
     echo/     Wscript.Sleep 200
     echo/ Next 
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "dir"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "exit"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     ) 

set "_temp_vbs=%temp%\_temp_file_4vbs_.vbs" &  start "" /b !_cmd_!
@"%Windir%\System32\cScript.exe" //nologo "!_temp_vbs!" <nul & del /q /f "!_temp_vbs!" & goto :eof

2) How about using the Telnet Script Tool to automate the sending of input data?


  • Below follows a example of the use of this tool that makes the insertion using the contents of a text file: "%temp%\script_ts.scr"
@echo off & setlocal enabledelayedexpansion & cls & mode con cols=77 lines=30

echo/ & color 9F & set "_usuario_=mardencmt" & set "_senha_=admin" & set "_ip_porta_=10.0.50.1 23"

>"%temp%\script_ts.scr" ^
    (
     echo/!_ip_porta_! & echo/WAIT "User Name" & echo/SEND "!_usuario_!\m" & echo/WAIT "Passoword" & echo/SEND "!_senha_!\m"
    ) && "%temp%\TST10.exe" /r:"%temp%\script_ts.scr" /o:"%temp%\output_ts.txt" & goto :eof

Browser other questions tagged

You are not signed in. Login or sign up in order to post.