Telnet

Started by gerrit, July 31, 2013, 02:38:47 AM

Previous topic - Next topic

gerrit

Iââ,¬â,,¢m trying to use WinBatch to do some telnetting.

When I start:  ââ,¬Å"telnet zispââ,¬Â
I get a blank screen with ââ,¬Å"Telnet zispââ,¬Â in titlebar
I type ââ,¬Å"cwzââ,¬Â+ [Enter]

Now the following text appears:

BOS-V16R20(201011) , Produktiesessie-CWZ-P02 , station  4906
Run   :      A0
Datum :31-07-13
Tijd  :   10:47
Usernummer?:

And I can type my usernumber and password to log in.

In Winbatch I wrote following code:

Code (winbatch) Select
AddExtender( "wwwsk44I.dll" )

socket = sOpen ( )
status = sConnect( socket, "zisp", "telnet" )
Message("Status:",status)

Sendres=sSendLine(socket,"cwz")
message("Send result:" ,sendres)

msg = sRecvLine( socket, 1024 )
Message( "Received:", msg )


Status returns  ââ,¬Å"1ââ,¬Â
Send result  = ââ,¬Å"1ââ,¬Â

But I get no result from the sRecvLine command.

Am I mistaken in expecting some of the text as was shown in the telnetscreen?
What am I doing wrong?

Regards,

Gerrit



Deana

sRecvLine should get a line of text from the socket, up to the first carriage return line feed. The sRecv___ functions all wait until the computer actually receives all the data the function is requesting.
sOK2Recv determines if there is currently enough data in the receive queue to return immediately.

Here is a generic code sample that uses both sOK2Send and sOK2Recv along with some additional error checking:

Code (winbatch) Select
AddExtender("WWWSK44I.DLL",0,"WWWSK64I.DLL")
socket = sOpen ()
counter=0
If socket != @FALSE
   status = sConnect ( socket, "www.yourdomain.com", "echo" )
   If status == @TRUE
      ;If for some reason you wanted to do sometime else while socket was occupied
      While !sOK2Send( socket )
         counter = counter+1 ; do something
      EndWhile
      sSendLine( socket, "yoohoo" )
      While !sOK2Recv( socket, 6 )
         counter = counter+1 ; do something
      EndWhile
      msg = sRecvLine( socket,256 )
      Message( "Received Message is", msg )
   Else
      err = wxGetLastErr( )
      msg = wxGetErrDesc( err )
      Message( "Winsock Error A %err%", msg )
   EndIf
   sClose( socket )
Else
   err = wxGetLastErr( )
   msg = wxGetErrDesc( err )
   Message( "Winsock Error B %err%", msg )
EndIf
Exit



Deana F.
Technical Support
Wilson WindowWare Inc.

ChuckC

The very first thing that you need to know is that Telnet is a protocol in and of its own that has handshaking requirements that go beyond what is required to simply establish a TCP connection to port 23 on a server.

There are RFC documents which describe the Telnet protocol specifications in detail, and you can do a Google search to find them online.  Once you read and understand them, you can write your script to properly implement the Telnet IAC Option Negotiation state machine logic.

Alternatively, if you'd like to get a jump start on this, I wrote a script many years ago that implemented the Telnet IAC Option Negotiation state machine logic to allow a WinBatch script to perform some simple automation of a Telnet session.  I made that code publicly available and it is available from the Wilson WindowWare Tech Support database as follows:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Samples~from~Users/Telnet+Telnet~Command~Line~Utility~For~Experts.txt

Read the online example and download the zip file that contains the script and other related information that you will want to examine.


gerrit

OK, it took some studying, but I think I know how he commandline utility works.

thanks very much for your help

Gerrit

kdmoyers

Quote from: ChuckC on August 01, 2013, 07:35:54 AM
Read the online example ...
Very educational Chuck thanks!!
The mind is everything; What you think, you become.