|
-
Apr 19th, 2004, 08:14 AM
#1
Thread Starter
Hyperactive Member
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:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Class UNIX_Connection
Public mySocket As Socket
Public IP As IPEndPoint
Public Connected As Boolean
Public Sub Connect(ByVal Server As String)
IP = New IPEndPoint(Dns.GetHostByName(Server).AddressList(0), 23)
mySocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Try
mySocket.Connect(IP)
Connected = True
Catch ex As Exception
Connected = False
End Try
End Sub
Public Sub SendData(ByVal Message As String)
If Connected = False Then
MessageBox.Show("No connection exists.")
Exit Sub
End If
Dim Buffer() As Byte = ASCIIEncoding.ASCII.GetBytes(Message)
mySocket.Send(Buffer, Buffer.Length, SocketFlags.None)
Dim ReceivedData(255) As Byte
mySocket.Receive(ReceivedData, 0, mySocket.Available, SocketFlags.None)
MessageBox.Show(ASCIIEncoding.ASCII.GetString(ReceivedData))
End Sub
Public Sub Disconnect()
mySocket.Shutdown(SocketShutdown.Both)
mySocket.Close()
Connected = False
End Sub
End Class
Any help would be fantastic.
"I'm Brian and so is my Wife"
-
Nov 10th, 2004, 10:20 AM
#2
Lively Member
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.
-
Nov 10th, 2004, 12:06 PM
#3
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|