Hello,
I have been trying to write something in VB.net 2010 that would allow me to log into several fiber channel switches over a telnet connection and perform some commands. After doing some research, I am processing the handshaking codes and getting into the human readable text. When prompted for the login, I provide the user name. It is echoed back to me, and then I am prompted for the password. This is provided, and then I get Login Incorrect back. Using the exact same name/pw through telnet.exe I am able to log in successfully.
I've tried terminating my lines with CR (x0D), LF (x0A) and CRLF (x0D0A), all with the same result. I'm not sure if maybe I'm missing something, or if I've done something wrong in my code. I know the following isn't the cleanest in the world. Ideally, I wouldn't be checking each line to see if it was time for the login or password, but I put this here to limit the number of places the problem could be. Socket definition is handled before this is called. Just tossed it out there for completeness.
Thoughts anyone?
I have been trying to write something in VB.net 2010 that would allow me to log into several fiber channel switches over a telnet connection and perform some commands. After doing some research, I am processing the handshaking codes and getting into the human readable text. When prompted for the login, I provide the user name. It is echoed back to me, and then I am prompted for the password. This is provided, and then I get Login Incorrect back. Using the exact same name/pw through telnet.exe I am able to log in successfully.
I've tried terminating my lines with CR (x0D), LF (x0A) and CRLF (x0D0A), all with the same result. I'm not sure if maybe I'm missing something, or if I've done something wrong in my code. I know the following isn't the cleanest in the world. Ideally, I wouldn't be checking each line to see if it was time for the login or password, but I put this here to limit the number of places the problem could be. Socket definition is handled before this is called. Just tossed it out there for completeness.
Thoughts anyone?
Code:
tnSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
tnSocket.ReceiveTimeout = 10000
Private Sub ReceiveText(ByVal NumBytes As Integer, ByVal RecvBytes As Byte(), ByVal RecvString As String)
Dim i As Integer = 0
Do Until (i >= 2 And Not NumBytes = 256)
Do
Try
NumBytes = 0
NumBytes = tnSocket.Receive(RecvBytes, 0, RecvBytes.Length, 0)
RecvString = Encoding.ASCII.GetString(RecvBytes, 0, NumBytes)
txtRecv.Text += RecvString & vbNewLine
If RecvString.Contains("login:") Then
Dim cmd As Byte() = SendThis("USERID" & vbCrLf)
tnSocket.Send(cmd, 0, cmd.Length, SocketFlags.None)
End If
If RecvString.Contains("assword") Then
Dim cmd As Byte() = SendThis("PASSWORD" & vbCrLf)
tnSocket.Send(cmd, 0, cmd.Length, SocketFlags.None)
End If
Catch ex As Exception
txtRecv.Text += "Error:" & ex.Message
End Try
Loop While NumBytes = 256
i += 1
Wait(3000)
Loop
End Sub
Private Function SendThis(ByVal send As String) As Byte()
Dim SendBytes As [Byte]() = Encoding.ASCII.GetBytes(send)
txtRecv.Text += "Sending:" & send & vbNewLine
Dim hexval As String
hexval = BitConverter.ToString(SendBytes, 0, SendBytes.Length)
txtRecv.Text += "Actual:" & hexval & vbNewLine
Return SendBytes
End Function