You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jason Dorsey <Ja...@netiq.com> on 2011/10/12 17:23:52 UTC

Telnet: Problems automating a session

Hey,

Very new to java socket programming and I am having an issue with automating a session to issue one command and then exit. When I use the commons telnet library I am able to connect and successfully run the command, but only when I interact with the prompt. When I try and simulate just issuing the commands it does not work. What seems to be happening is that instead of writing each command as a separate packet, all the commands are being sent in the same packet (validated this with wireshark).

What I have checked.


1.       The batch file does work locally on the system.

2.       The command does work when typed into a telnet session (validated with tcpview).

3.       The non-working version does connect to the remote system.

4.       The correct auth information is being passed to the function call.

Setup that works:


Just like the weather demo

My faulty setup:

Append the user, pass, command and exit strings with "\r\n". (user += "\r\n";)
And with each item I:
                Convert them into a ByteArrayInputStream (in = new ByteArrayInputStream(user.getBytes());)
                Invoke Util.copyStream (Util.copyStream(in, remoteOutput); ) // where remoteOutput is the telnet's outputstream

Thanks

Jason Dorsey | Engineering Intern


RE: Telnet: Problems automating a session

Posted by Jason Dorsey <Ja...@netiq.com>.
Thanks Sebb,

I did study the example. I found the issue. It seems that the commands I was sending were being received too fast for the telnet server to keep up. When I instituted a sleep for the current thread and played with the interval it started to work.

Jason Dorsey | Engineering Intern

-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com] 
Sent: Wednesday, October 12, 2011 12:03 PM
To: Commons Users List
Subject: Re: Telnet: Problems automating a session

On 12 October 2011 17:13, Jason Dorsey <Ja...@netiq.com> wrote:
> Thanks Daniel,
>
> I tried that and still no joy, but I think that I see the issue now.
>
> Upon inspecting the traces that work vs. my own I see a very sharp difference.
>
> The server sends back:
>
> Command: Do Authentication Option
> Command: Will Echo
> Command: Will Suppress Go Ahead
> Command: Do New Environment Option
> Command: Do Negotiate About Window Size
> Command: Do Binary Transmission
> Command: Will Binary Transmission
>
> It is expecting: (based on the trace that works)
>
> Command: Won't Authentication Option
>
> But instead I am sending it the username right away.
>
> How do I send the "Won't Authenticate Option" command?
>
> I think this requires the use of a TelnetCommand and TelnetOption, but I am unsure of the format.

Have you studied the example:

http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/telnet/TelnetClientExample.java?view=markup

> Jason Dorsey | Engineering Intern
>
>
> -----Original Message-----
> From: Daniel Pitts [mailto:Daniel@coloraura.com]
> Sent: Wednesday, October 12, 2011 10:29 AM
> To: Commons Users List
> Cc: user@commons.apache.org
> Subject: Re: Telnet: Problems automating a session
>
> Try calling outputStream.flush() after each command.
>
> Thanks,
> Daniel.
>
> Sent from my iPhone
>
> On Oct 12, 2011, at 8:23 AM, Jason Dorsey <Ja...@netiq.com> wrote:
>
>> Hey,
>>
>> Very new to java socket programming and I am having an issue with automating a session to issue one command and then exit. When I use the commons telnet library I am able to connect and successfully run the command, but only when I interact with the prompt. When I try and simulate just issuing the commands it does not work. What seems to be happening is that instead of writing each command as a separate packet, all the commands are being sent in the same packet (validated this with wireshark).
>>
>> What I have checked.
>>
>>
>> 1.       The batch file does work locally on the system.
>>
>> 2.       The command does work when typed into a telnet session (validated with tcpview).
>>
>> 3.       The non-working version does connect to the remote system.
>>
>> 4.       The correct auth information is being passed to the function call.
>>
>> Setup that works:
>>
>>
>> Just like the weather demo
>>
>> My faulty setup:
>>
>> Append the user, pass, command and exit strings with "\r\n". (user +=
>> "\r\n";) And with each item I:
>>                Convert them into a ByteArrayInputStream (in = new 
>> ByteArrayInputStream(user.getBytes());)
>>                Invoke Util.copyStream (Util.copyStream(in, 
>> remoteOutput); ) // where remoteOutput is the telnet's outputstream
>>
>> Thanks
>>
>> Jason Dorsey | Engineering Intern
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Telnet: Problems automating a session

Posted by sebb <se...@gmail.com>.
On 12 October 2011 17:13, Jason Dorsey <Ja...@netiq.com> wrote:
> Thanks Daniel,
>
> I tried that and still no joy, but I think that I see the issue now.
>
> Upon inspecting the traces that work vs. my own I see a very sharp difference.
>
> The server sends back:
>
> Command: Do Authentication Option
> Command: Will Echo
> Command: Will Suppress Go Ahead
> Command: Do New Environment Option
> Command: Do Negotiate About Window Size
> Command: Do Binary Transmission
> Command: Will Binary Transmission
>
> It is expecting: (based on the trace that works)
>
> Command: Won't Authentication Option
>
> But instead I am sending it the username right away.
>
> How do I send the "Won't Authenticate Option" command?
>
> I think this requires the use of a TelnetCommand and TelnetOption, but I am unsure of the format.

Have you studied the example:

http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/telnet/TelnetClientExample.java?view=markup

> Jason Dorsey | Engineering Intern
>
>
> -----Original Message-----
> From: Daniel Pitts [mailto:Daniel@coloraura.com]
> Sent: Wednesday, October 12, 2011 10:29 AM
> To: Commons Users List
> Cc: user@commons.apache.org
> Subject: Re: Telnet: Problems automating a session
>
> Try calling outputStream.flush() after each command.
>
> Thanks,
> Daniel.
>
> Sent from my iPhone
>
> On Oct 12, 2011, at 8:23 AM, Jason Dorsey <Ja...@netiq.com> wrote:
>
>> Hey,
>>
>> Very new to java socket programming and I am having an issue with automating a session to issue one command and then exit. When I use the commons telnet library I am able to connect and successfully run the command, but only when I interact with the prompt. When I try and simulate just issuing the commands it does not work. What seems to be happening is that instead of writing each command as a separate packet, all the commands are being sent in the same packet (validated this with wireshark).
>>
>> What I have checked.
>>
>>
>> 1.       The batch file does work locally on the system.
>>
>> 2.       The command does work when typed into a telnet session (validated with tcpview).
>>
>> 3.       The non-working version does connect to the remote system.
>>
>> 4.       The correct auth information is being passed to the function call.
>>
>> Setup that works:
>>
>>
>> Just like the weather demo
>>
>> My faulty setup:
>>
>> Append the user, pass, command and exit strings with "\r\n". (user +=
>> "\r\n";) And with each item I:
>>                Convert them into a ByteArrayInputStream (in = new ByteArrayInputStream(user.getBytes());)
>>                Invoke Util.copyStream (Util.copyStream(in,
>> remoteOutput); ) // where remoteOutput is the telnet's outputstream
>>
>> Thanks
>>
>> Jason Dorsey | Engineering Intern
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: Telnet: Problems automating a session

Posted by Jason Dorsey <Ja...@netiq.com>.
Thanks Daniel,

I tried that and still no joy, but I think that I see the issue now.

Upon inspecting the traces that work vs. my own I see a very sharp difference.

The server sends back:

Command: Do Authentication Option
Command: Will Echo
Command: Will Suppress Go Ahead
Command: Do New Environment Option
Command: Do Negotiate About Window Size
Command: Do Binary Transmission
Command: Will Binary Transmission

It is expecting: (based on the trace that works)

Command: Won't Authentication Option

But instead I am sending it the username right away.

How do I send the "Won't Authenticate Option" command?

I think this requires the use of a TelnetCommand and TelnetOption, but I am unsure of the format.

Jason Dorsey | Engineering Intern


-----Original Message-----
From: Daniel Pitts [mailto:Daniel@coloraura.com] 
Sent: Wednesday, October 12, 2011 10:29 AM
To: Commons Users List
Cc: user@commons.apache.org
Subject: Re: Telnet: Problems automating a session

Try calling outputStream.flush() after each command. 

Thanks,
Daniel.

Sent from my iPhone

On Oct 12, 2011, at 8:23 AM, Jason Dorsey <Ja...@netiq.com> wrote:

> Hey,
> 
> Very new to java socket programming and I am having an issue with automating a session to issue one command and then exit. When I use the commons telnet library I am able to connect and successfully run the command, but only when I interact with the prompt. When I try and simulate just issuing the commands it does not work. What seems to be happening is that instead of writing each command as a separate packet, all the commands are being sent in the same packet (validated this with wireshark).
> 
> What I have checked.
> 
> 
> 1.       The batch file does work locally on the system.
> 
> 2.       The command does work when typed into a telnet session (validated with tcpview).
> 
> 3.       The non-working version does connect to the remote system.
> 
> 4.       The correct auth information is being passed to the function call.
> 
> Setup that works:
> 
> 
> Just like the weather demo
> 
> My faulty setup:
> 
> Append the user, pass, command and exit strings with "\r\n". (user += 
> "\r\n";) And with each item I:
>                Convert them into a ByteArrayInputStream (in = new ByteArrayInputStream(user.getBytes());)
>                Invoke Util.copyStream (Util.copyStream(in, 
> remoteOutput); ) // where remoteOutput is the telnet's outputstream
> 
> Thanks
> 
> Jason Dorsey | Engineering Intern
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Telnet: Problems automating a session

Posted by Daniel Pitts <Da...@coloraura.com>.
Try calling outputStream.flush() after each command. 

Thanks,
Daniel.

Sent from my iPhone

On Oct 12, 2011, at 8:23 AM, Jason Dorsey <Ja...@netiq.com> wrote:

> Hey,
> 
> Very new to java socket programming and I am having an issue with automating a session to issue one command and then exit. When I use the commons telnet library I am able to connect and successfully run the command, but only when I interact with the prompt. When I try and simulate just issuing the commands it does not work. What seems to be happening is that instead of writing each command as a separate packet, all the commands are being sent in the same packet (validated this with wireshark).
> 
> What I have checked.
> 
> 
> 1.       The batch file does work locally on the system.
> 
> 2.       The command does work when typed into a telnet session (validated with tcpview).
> 
> 3.       The non-working version does connect to the remote system.
> 
> 4.       The correct auth information is being passed to the function call.
> 
> Setup that works:
> 
> 
> Just like the weather demo
> 
> My faulty setup:
> 
> Append the user, pass, command and exit strings with "\r\n". (user += "\r\n";)
> And with each item I:
>                Convert them into a ByteArrayInputStream (in = new ByteArrayInputStream(user.getBytes());)
>                Invoke Util.copyStream (Util.copyStream(in, remoteOutput); ) // where remoteOutput is the telnet's outputstream
> 
> Thanks
> 
> Jason Dorsey | Engineering Intern
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org