Author Topic: Telnet  (Read 3594 times)

gerrit

  • Newbie
  • *
  • Posts: 2
Telnet
« 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
Usernummer?:

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("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

  • 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
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

  • 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:

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

  • 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

Gerrit

kdmoyers

  • 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.