ola, estou com um problema em criar um cliente de telnet para fazer comunicação com o mikrotik,
segue o codigo abaixo para alguem pode me da uma ajuda.
estou usando o componente Active Socket 4.1 type Library
Option Explicit
Dim objSocket As Tcp
Dim objConstants As SocketConstants
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const MAX_PATH = 260
Private Sub CommandConnect_Click()
objSocket.Connect TextHost, CInt(TextPort.Text)
If (ShowResult() = 0) Then
CommandSubmit.Enabled = True
CommandDisconnect.Enabled = True
CommandConnect.Enabled = False
End If
End Sub
Private Sub CommandDisconnect_Click()
objSocket.Disconnect
If (ShowResult() = 0) Then
CommandSubmit.Enabled = False
CommandDisconnect.Enabled = False
CommandConnect.Enabled = True
End If
End Sub
Private Sub CommandSubmit_Click()
objSocket.SendString TextCommand
ShowResult
End Sub
Private Sub CommandView_Click()
If FileExists(TextLogFile.Text) = True Then
Shell "notepad " + TextLogFile.Text, vbNormalFocus
End If
End Sub
Public Function FileExists(sFileName As String) As Boolean
FileExists = CBool(Len(Dir$(sFileName))) And CBool(Len(sFileName))
End Function
Private Function SetDefaultLogFile()
Dim Buffer As String
Buffer = Space(MAX_PATH)
If GetTempPath(MAX_PATH, Buffer) <> 0 Then
TextLogFile.Text = Left$(Buffer, InStr(Buffer, vbNullChar) - 1) & "TelnetLog.txt"
Else
TextLogFile.Text = "C:\TelnetLog.txt"
End If
End Function
Private Sub Form_Load()
Set objSocket = CreateObject("ActiveXperts.Tcp")
Set objConstants = CreateObject("ActiveXperts.ASConstants")
objSocket.Protocol = objConstants.asSOCKET_PROTOCOL_TELNET
SetDefaultLogFile
End Sub
Private Sub Timer_Timer()
While objSocket.HasData
TextReceived.Text = TextReceived & objSocket.ReceiveString & vbCrLf
Wend
End Sub
Private Function ShowResult()
ShowResult = objSocket.LastError
TextResult.Caption = ShowResult & " : " & objSocket.GetErrorDescription(ShowResult)
End Function
tentei fazer com o winsock so que não tive sucesso também...
fico no aguardo.