Computer Hope

Software => Computer programming => Topic started by: ann124 on November 23, 2004, 06:55:58 AM

Title: login to telnet from batch script
Post by: ann124 on November 23, 2004, 06:55:58 AM
I was able to set up a batch file to open a telnet session, but I still have to type in my username and password for the session to actually start. Is there any way to set up the batch file to automatically enter my username and password? ???
Title: Re: login to telnet from batch script
Post by: tamby1981 on January 14, 2005, 08:19:45 AM
Hello friend
Please if you find a solution for this problem please send it to my mail address
[email protected]
Title: Re: login to telnet from batch script
Post by: Zzyzx on January 14, 2005, 09:52:02 AM
Try using some Telnet switches:

Examples:

telnet -a 192.168.2.1

or

telnet -l username 192.168.2.1

There is no switch for the password. The "a" switch will try automatic logon using your signon from your machine. The "l" switch allows you to enter any username.

Hope this helps.
8)
Title: Re: login to telnet from batch script
Post by: MMaverick on January 15, 2005, 05:38:33 AM
You can also try having dos automatically put some input to the program through piping with the echo command.

See the following example:
Code: [Select]
echo y|copy file1.zip "D:\Program Files\file1.zip"

The echo pipes "y" to the copy program which is the answer to the question "Do you want to overwrite the existing file".

Maybe you can do the same with telnet
Title: Re: login to telnet from batch script
Post by: z_c00l on May 21, 2007, 07:45:28 PM

This is good. from this command we can login the username, but how do we login the password?

Try using some Telnet switches:

Examples:

telnet -a 192.168.2.1

or

telnet -l username 192.168.2.1

There is no switch for the password. The "a" switch will try automatic logon using your signon from your machine. The "l" switch allows you to enter any username.

Hope this helps.
 8)
Title: Re: login to telnet from batch script
Post by: Sidewinder on May 22, 2007, 03:50:12 AM
Like a phoenix rising from the ashes, old posts spring forth to haunt us. You do realize this post is over 2 years old, right?

You may need a working knowledge of how telnet prompts for parameters. Try combining the two responses above:

echo password | telnet -l username IPaddress

Be aware that putting unencrypted passwords into scripts/batch files is a security breach. Many programs will choke on the pipe; let's hope Microsoft followed their own standards.

Good luck. 8)
Title: Re: login to telnet from batch script
Post by: z_c00l on May 22, 2007, 06:12:52 AM
Thanks for the reply..
I'm not too sure where this comes in...

I have created a ".BAT" file inside it has this commands

----------------------------------------
c:\windows\system32\telnet.exe
----------------------------------------

this will open the telnet. Where do I go from here?
I would like to login the username and password using the BAT file. is this possible?

Title: Re: login to telnet from batch script
Post by: Sidewinder on May 22, 2007, 06:46:54 AM
Did you run what was posted?

echo password | telnet -l username IPaddress

What were the results? Can you post the console output. If  telnet cannot accept input from the pipe, it may be possible to redirect input from a file, but it will be necessary to see the sequence telnet requests the input.

Of course telnet may only take the password from the keyboard in which case you will be SOL.

Let us know. 8)

If the telnet userid and password are the same ones you use for Windows, try using the -a switch:

Code: [Select]
telnet -a IPaddress
Title: Re: login to telnet from batch script
Post by: ghostdog74 on May 22, 2007, 07:57:51 AM
alternatively you can use other languages such as Perl that  has telnet modules to do this task.
eg
Code: [Select]
    use Net::Telnet ();
    $t = new Net::Telnet (Timeout => 10,
                          Prompt => '/bash\$ $/');
    $t->open("hostname");
    $t->login($username, $passwd);
    @lines = $t->cmd("who");
    print @lines;
more information here (http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm) if you are interested.
Title: Re: login to telnet from batch script
Post by: georgd on July 23, 2014, 11:25:28 PM
Yes. It is possible with help of another executable called telnetd.exe. I have developed this executable to automate telnetd.exe(http://myresearchdev.blogspot.sg/) session using windows batch file.

Usage

telnetd.exe script.txt

scripts.txt -> for the telnet commands



After the execution of the batch file you can seelogs from telnetlog.txt. This telnetlog.txt will help you to troubleshoot the commands and responses.