Author Topic: Telnet  (Read 3594 times)


  • Newbie
  • *
  • Posts: 2
« on: July 31, 2013, 02:38:47 am »
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

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

In Winbatch I wrote following code:

Code: Winbatch
AddExtender( "wwwsk44I.dll" )

socket = sOpen ( )
status = sConnect( socket, "zisp", "telnet" )

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?




  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Telnet
« Reply #1 on: July 31, 2013, 07:59:55 am »
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
socket = sOpen ()
If socket != @FALSE
   status = sConnect ( socket, "", "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
      sSendLine( socket, "yoohoo" )
      While !sOK2Recv( socket, 6 )
         counter = counter+1 ; do something
      msg = sRecvLine( socket,256 )
      Message( "Received Message is", msg )
      err = wxGetLastErr( )
      msg = wxGetErrDesc( err )
      Message( "Winsock Error A %err%", msg )
   sClose( socket )
   err = wxGetLastErr( )
   msg = wxGetErrDesc( err )
   Message( "Winsock Error B %err%", msg )

Deana F.
Technical Support
Wilson WindowWare Inc.


  • Full Member
  • ***
  • Posts: 192
Re: Telnet
« Reply #2 on: August 01, 2013, 07:35:54 am »
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:

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


  • Newbie
  • *
  • Posts: 2
Re: Telnet
« Reply #3 on: August 06, 2013, 04:33:20 am »
OK, it took some studying, but I think I know how he commandline utility works.

thanks very much for your help



  • Sr. Member
  • ****
  • Posts: 307
Re: Telnet
« Reply #4 on: August 06, 2013, 05:57:56 am »
Read the online example ...
Very educational Chuck thanks!!
The mind is everything; What you think, you become.