Results 1 to 3 of 3

Thread: Telnet To UNIX Server

  1. #1

    Thread Starter
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307

    Telnet To UNIX Server

    Hi Everybody,

    I'm trying to TELNET to a UNIX server from within my VB .NET proggy.

    I can connect up to the server on Port 23, no problem, using a Socket.

    My problem is sending commands to the Socket and receiving anything intelligible back.

    The only data I'm able to get back from the server is the string below:-

    "}} }#}}'}$

    This happens on the first pass of the code. If I then disconnect the socket, close it and re-open it, all I get back is an empty string!

    Here's the code I'm using (I have never used Sockets before btw!).

    VB Code:
    1. Imports System.Net
    2. Imports System.Net.Sockets
    3. Imports System.Text
    4.  
    5. Class UNIX_Connection
    6.  
    7. Public mySocket As Socket
    8. Public IP As IPEndPoint
    9. Public Connected As Boolean
    10.  
    11. Public Sub Connect(ByVal Server As String)
    12.  
    13. IP = New IPEndPoint(Dns.GetHostByName(Server).AddressList(0), 23)
    14. mySocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
    15. Try
    16. mySocket.Connect(IP)
    17. Connected = True
    18. Catch ex As Exception
    19. Connected = False
    20. End Try
    21.  
    22. End Sub
    23.  
    24. Public Sub SendData(ByVal Message As String)
    25.  
    26. If Connected = False Then
    27. MessageBox.Show("No connection exists.")
    28. Exit Sub
    29. End If
    30.  
    31. Dim Buffer() As Byte = ASCIIEncoding.ASCII.GetBytes(Message)
    32. mySocket.Send(Buffer, Buffer.Length, SocketFlags.None)
    33.  
    34. Dim ReceivedData(255) As Byte
    35. mySocket.Receive(ReceivedData, 0, mySocket.Available, SocketFlags.None)
    36.  
    37. MessageBox.Show(ASCIIEncoding.ASCII.GetString(ReceivedData))
    38.  
    39. End Sub
    40.  
    41. Public Sub Disconnect()
    42.  
    43. mySocket.Shutdown(SocketShutdown.Both)
    44. mySocket.Close()
    45. Connected = False
    46.  
    47. End Sub
    48.  
    49. End Class

    Any help would be fantastic.
    "I'm Brian and so is my Wife"

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Posts
    77
    Yes. I am getting the same thing in VB5 and .NET

    It works fine for telnetting to a Cisco firewall for administation of it. BUT when connecting to a unix box or IBM mainframe you get rubbish back despite both of these working with DOS telnet.

    I suspect that a string has to be sent to tell the other end what type of terminal you are running (VT100 VT320 etc).

    I don't know for sure but next week I will get my LAN analyser out and capture what DOS does when it connects.

  3. #3
    Lively Member
    Join Date
    Sep 2002
    Posts
    77
    had a look.

    its not just rubbish you are getting.

    the server sends FF FD xx (where xx is a hex character)

    If you prefer it sends chr(255)+chr(253)+chr(?)

    the 255 means "interpret as command"
    the 253 means "suboption negotiate DO"

    the ? means various options EG. x18 = terminal type

    I managed to get a login prompt from an IBM mainframe by sending:

    chr(255)+chr(252)+chr(?) in response to each request to negotiate which basic means WONT negotiate the option.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width