vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Top-Preis! AP-Access-Tools-CD Volume 1  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Visual-Basic Einsteiger
Re: VB & Telnet 
Autor: PJ_Shorty
Datum: 03.01.06 01:03

Das Winsockcontrol beherrscht kein Telnet,
habs aber auch mal gebraucht und einen Weg gefunden
Du brauchst eine Form(LinuxSteuerung), Winsock (sckMain), Timer (Timer1), Label (Label1)

Option Explicit
Private ip As String
Private port As Integer
Private strData As Variant
Private sendstr(10) As String
Private tmpstr As String
Private n As Integer
Private Connection As Boolean
Public LinuxAktion As String
Public LinuxUser As String
Public LinuxPW As String
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
 
 
'------------------------'
 
Private Sub Form_Load()
    MousePointer = vbHourglass
    'initialize variables
    sendstr(0) = ""
    sendstr(1) = ""
    sendstr(2) = ""
    sendstr(3) = LinuxUser             'Username
    sendstr(4) = LinuxPW & vbCrLf      'Passwort
    sendstr(5) = LinuxAktion & vbCrLf  'z.b."reboot" & vbCrLf  'Befehl
    n = -1
    Connection = False
    Call Connect
    Timer1.Enabled = True
End Sub
 
Private Sub Connect()
    Label1.Caption = "Verbinde..."
    'initialize variables
    ip = "172.16.2.26"  'ip address of unix machine your connecting to
    port = 23       '23 is the std telnet port
 
    'reset the socket
    sckMain.Close
 
    'set the new properties
    sckMain.RemoteHost = ip
    sckMain.RemotePort = port
 
    'initiate the connection
    sckMain.Connect
End Sub
 
Private Sub sckMain_Connect()
    Label1.Caption = "Verbindung OK"
    Connection = True
    Sleep (100)
End Sub
 
Private Sub sckMain_DataArrival(ByVal bytesTotal As Long)
    'initialize the variable
    strData = ""
    'get the data
    sckMain.GetData strData ', vbString
 
    If n < 3 Then
        sendstr(n + 1) = strData & sendstr(n + 1)
    End If
         n = n + 1
        If n > 6 Then
            Connection = False
            Unload Me
            Exit Sub
        End If
        tmpstr = sendstr(n)
        If sckMain.State = sckConnected Then
            Label1.Caption = "Sende Daten..."
            sckMain.SendData tmpstr
            DoEvents
        Else
            If Connection = False Then
                Timer1.Enabled = False
                MousePointer = vbDefault
                MsgBox "Keine Verbindung zum Linux-Rechner!"
                Unload Me
            End If
        End If
End Sub
 
Private Sub sckMain_Error(ByVal Number As Integer, Description As String, _
                          ByVal Scode As Long, ByVal Source As String, _
                          ByVal HelpFile As String, ByVal HelpContext As Long, _
                          CancelDisplay As Boolean)
    'alert the user to the error
    MsgBox "Error: " & Description
End Sub
 
Private Sub sckMain_SendComplete()
    Label1.Caption = "Daten gesendet"
End Sub
 
 
 
Private Sub Timer1_Timer()
        If sckMain.State = sckConnected Then
        ElseIf Connection = False Then
            MousePointer = vbDefault
            MsgBox "Zeitüberschreitung bei Verbindung!"
            FrmMain.Show
            Connection = False
            Timer1.Enabled = False
            Unload Me
            Exit Sub
        End If
        Timer1.Enabled = False
End Sub
ich benutz das für einen Linuxrechner den ich über Telnet fernsteuer und läuft perfekt.
Damit kann ich einen Befehl senden (z.b. reboot)
Ich ruf diese Form auf mit z.b.:

Private Sub TelnetStart(User as String, Pw as String, Action as String)
   With LinuxSteuerung
      .LinuxUser = User
      .LinuxPW = Pw
      .LinuxAktion = Action
      Call .Show(vbModal)
   End With
End Sub
hoffe das hilft dir weiter.

mfg
Shorty

------------------------------------------------

man lernt nie aus...

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
VB & Telnet1.359ipstyle0002.01.06 15:03
Re: VB & Telnet937ICE-MAN02.01.06 15:11
Re: VB & Telnet778ipstyle0002.01.06 15:33
Re: VB & Telnet865PJ_Shorty03.01.06 01:03
Re: VB & Telnet803ipstyle0003.01.06 07:32
Re: VB & Telnet790PJ_Shorty03.01.06 11:50
Re: VB & Telnet785ICE-MAN03.01.06 12:06
Re: VB & Telnet789PJ_Shorty03.01.06 12:13
Re: VB & Telnet834ICE-MAN03.01.06 15:49
Re: VB & Telnet878ipstyle0003.01.06 16:39
Re: VB & Telnet848ICE-MAN03.01.06 16:56
Re: VB & Telnet794ipstyle0003.01.06 21:35
Re: VB & Telnet783ICE-MAN03.01.06 22:08
Re: VB & Telnet970ipstyle0003.01.06 22:13
Re: VB & Telnet788ICE-MAN03.01.06 22:19
Re: VB & Telnet821ipstyle0003.01.06 22:23
Re: VB & Telnet756PJ_Shorty03.01.06 22:20
Re: VB & Telnet731ipstyle0003.01.06 22:29
Re: VB & Telnet784PJ_Shorty03.01.06 22:35
Re: VB & Telnet796ipstyle0003.01.06 22:50
Re: VB & Telnet736ICE-MAN03.01.06 23:16
Re: VB & Telnet809PJ_Shorty03.01.06 23:22
Re: VB & Telnet765PJ_Shorty03.01.06 17:13
Re: VB & Telnet739ipstyle0003.01.06 13:13
Re: VB & Telnet777OldMan03.01.06 13:29
Re: VB & Telnet895ipstyle0003.01.06 13:59
Re: VB & Telnet771PJ_Shorty03.01.06 17:10
Re: VB & Telnet755ipstyle0003.01.06 23:44
Re: VB & Telnet835PJ_Shorty04.01.06 00:01
Re: VB & Telnet741PJ_Shorty04.01.06 00:01
Re: VB & Telnet715ipstyle0009.01.06 10:35
Re: VB & Telnet733ipstyle0009.01.06 13:33
Re: VB & Telnet739PJ_Shorty09.01.06 13:38
Re: VB & Telnet794ipstyle0009.01.06 13:56
Re: VB & Telnet727PJ_Shorty09.01.06 15:09
Re: VB & Telnet777ipstyle0013.01.06 11:25
Re: VB & Telnet794PJ_Shorty13.01.06 19:03

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel