Solved

Cannot use Winsock control on telnet session

Posted on 2001-07-24
10
455 Views
Last Modified: 2013-11-13
Is is possible to use winsock control to open a telnet session?

I used winsock to open ftp and smtp successful, but fail on get respond from telnet session.

Any alternative way to talk with telnet using VB?

Thanks.
0
Comment
Question by:saikit
  • 6
  • 3
10 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 6316058
Winock does work with Telnet so either your code needs enhancing or the server is not listening for telnet. First try connecting to the server via Windows Telnet.exe, just to prove it works, then post your code here.
0
 

Author Comment

by:saikit
ID: 6316110
My code is as below:
-----------------------

Private Sub ConnectTelnet_Click()
   Dim strData As String
   Winsock1.Connect "172.22.23.6", 23
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
   Dim strData As String
   Winsock1.GetData strData
   Debug.Print strData
End Sub

------------------------
The resume of strData is not a readable characters. It should be the greeting message of my Linux box.

Please help. Thank you very much.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6316246
Try:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim Answer As String
   
    Answer = String$(bytesTotal, 0)
   
    If winsock1.State = sckConnected Then
        winsock1.GetData Answer, vbString, bytesTotal
        Debug.Print Answer
    End If
   
End Sub
0
 

Author Comment

by:saikit
ID: 6316276
I have jusr tried your code.
The result is same.. not working.

In the debug windows return a string "????"
(Four question mark with spaces)
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6316387
Don't forget the the telnet host is expecting you to be a dum terminal and will be expecting you to understand control codes.  So you may need to decode the data before displaying it.  For example ansi bbs, etc.


I don't use the connect syntax that you are using I use something like:

Private Sub cmdConnect_Click()
    If Me.wSock.State = sckClosed Then
        ' First connect to server.
        Me.wSock.RemoteHost = txtHost.Text
       
        Me.wSock.RemotePort = Val(txtPort.Text) ' normally 23
        Me.wSock.LocalPort = 0
        Me.wSock.Connect
        Me.wSock.Protocol = sckTCPProtocol

        Do While True
            If Me.wSock.State = sckConnected Then
                Exit Do
            ElseIf Me.wSock.State = sckError Then
                MsgBox "Impossible to connect to server.", vbExclamation + vbOKOnly, "Error connecting."
                Exit Sub
            End If
            DoEvents
        Loop
    Else
        MsgBox "Please disconnect before connecting again.", vbInformation, "Error connecting."
        Exit Sub
    End If
    statusB.SimpleText = "Connected to " + txtHost.Text + ". Local IP adress : " + wSock.LocalIP + ". Remote host IP : " + wSock.RemoteHostIP + "."
    statusB.Refresh
   
End Sub

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 17

Expert Comment

by:inthedark
ID: 6316400
Sorry I did protocol in formload and just dropped it in without thinking exchange these lines:
 Me.wSock.Connect
 Me.wSock.Protocol = sckTCPProtocol

like:
 Me.wSock.Protocol = sckTCPProtocol
 Me.wSock.Connect
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6316425
Further the response may not be ascii.
0
 

Author Comment

by:saikit
ID: 6316438
I followed and tried your code for connecting (set protocol to TCP before connect), but the result is same as before (four questions mark & spaces returned). Not working.

How to get the response to be readable character?
0
 
LVL 17

Accepted Solution

by:
inthedark earned 100 total points
ID: 6316949
Have you tried looking somewhere like here for a working example:

http://www.planet-source-code.com/xq/ASP/txtCodeId.11025/lngWId.1/qx/vb/scripts/ShowCode.htm
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7161517
Hi saikit,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept inthedark's comment(s) as an answer.

saikit, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now