Bonjour a tous,

Je souhaiterais exécuter une commande telnet, avec récupération du retour fait de la machine distante.
Sous dos la comme telnet, fonctionne correctement, pour cela je fais telnet xxxxx , puis controle A puis ma commande.

j'ai trouvé ce code, qui a priori doit fonctionner, mais dans ma texte box je n'ai aucun retour.
je pense que mon CTRL A ne fonctionne pas. J'ai essayé plusieurs méthodes pour effectuer mon CTRL A, mais sans succès.

Ci dessous le code, si vous avez une solution, je suis preneur. merci


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports System.Text
 
Public Class Form1
 
    Private oTCPStream As Net.Sockets.NetworkStream
 
    Private oTCP As New Net.Sockets.TcpClient()
 
    Private bytWriting As [Byte]()
 
    Private bytReading As Byte()
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Try
            TextBox3.Text = ""
            TextBox3.Text = "DEMMARRAGE ... "
            System.Threading.Thread.Sleep(5)
            oTCP.SendTimeout = 1500
            System.Threading.Thread.Sleep(50)
            oTCP.Connect("192.168.1.81", "23")
            TextBox3.Text = "connexion ... en cours "
            oTCPStream = oTCP.GetStream
 
            'TextBox1.Text = TextBox1.Text & ReadData() & vbCrLf 'Reads data from switch/server and displays it in a textbox
            WriteData("☺A20" & vbCrLf) 'This line can repeated as many times as you like. You just need to adjust the time the application waits before starting the next line of code.
 
            TextBox3.Text = "commande envoyé "
 
            System.Threading.Thread.Sleep(500) 'Pauses the application before starting the next line of code.
 
            TextBox1.Text = TextBox1.Text & ReadData() & vbCrLf
            oTCPStream.Close() 'Closed the NetworkStream
 
            oTCP.Close() 'Closed the TcpClient/Socket
 
            MsgBox("connection CLOSE")
 
        Catch Err As Exception
 
            MsgBox(Err.ToString)
 
        End Try
 
    End Sub
 
 
    Private Function ReadData() As String
 
        Dim sData As String
 
        ReDim bytReading(oTCP.ReceiveBufferSize)
 
        oTCPStream.Read(bytReading, 0, oTCP.ReceiveBufferSize)
 
        sData = Trim(System.Text.Encoding.ASCII.GetString(bytReading))
 
        ReadData = sData
 
    End Function
 
    Private Sub WriteData(ByVal sData As String)
 
        bytWriting = System.Text.Encoding.ASCII.GetBytes(sData)
 
        oTCPStream.Write(bytWriting, 0, bytWriting.Length)
 
    End Sub
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 
        TextBox3.Text = " ... "
 
    End Sub
End Class