- 1 year ago
Passing additional "arguments" to a telnet connection command
When using the telnet
command to connect to a remote server, you can't directly pass additional arguments to the telnet command itself. However, you can use a workaround by creating a script or a batch file that contains the telnet commands and the additional arguments you want to pass.
Here's an example of how you can achieve this:
- Create a text file named
commands.txt
that contains the commands you want to execute on the remote server. For example:
command1
command2 arg1 arg2
- Create a batch file (e.g.,
telnet_script.bat
) that invokes the telnet command and redirects the commands from thecommands.txt
file:
batch@echo off
echo open remote_server_ip port_number > telnet_commands.txt
echo user username password >> telnet_commands.txt
type commands.txt >> telnet_commands.txt
echo exit >> telnet_commands.txt
telnet < telnet_commands.txt
Replace remote_server_ip
, port_number
, username
, and password
with the appropriate values for your telnet connection.
Save the batch file and the
commands.txt
file in the same directory.Double-click the batch file (
telnet_script.bat
) to execute the telnet connection with the additional arguments.
The batch file will first create a temporary file telnet_commands.txt
, which contains the necessary telnet commands to open the connection, log in (if required), and execute the commands from commands.txt
. It then runs the telnet
command with the input redirection (<
) from the temporary file.
Please note that using telnet in scripts or batch files with hardcoded credentials may not be secure. It's better to use a more secure method of communication like SSH, especially if you are automating tasks or using telnet over unsecured networks.