Bonsoir,
Je suis en train de faire un client telnet mais j'ai deux bug dans mon code. Le premier est que la textbox1 n'affiche pas les commandes effectuées, je comprend pas pourquoi le .ReadToEnd ne fonctionne pas, faut t-il que toutes les opérations soient faites pour que cela marche ?
Le second fait tourner en rond le prog, c'est à mon avis une erreur de syntaxe au niveau de :
Peut être que c'est encore le .ReadToEnd
Code : Sélectionner tout - Visualiser dans une fenêtre à part If (sOut.ReadToEnd).Contains("login:") Then
Pour activer le telnet sur votre vista/7 allez dans Démarrer> panneau de conf.> programmes> activer ou désactiver des fonctions windows. Puis cochez "Client Telnet".
Dans un projet vb.net, mettez une textbox1 avec ce code dans un bouton.
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 Dim myProcess As Process = New Process() myProcess.StartInfo.FileName = "cmd.exe" myProcess.StartInfo.UseShellExecute = False myProcess.StartInfo.CreateNoWindow = True myProcess.StartInfo.RedirectStandardInput = True myProcess.StartInfo.RedirectStandardOutput = True myProcess.StartInfo.RedirectStandardError = True myProcess.Start() Dim sIn As StreamWriter = myProcess.StandardInput sIn.AutoFlush = True Dim sOut As StreamReader = myProcess.StandardOutput Dim sErr As StreamReader = myProcess.StandardError sIn.Write("telnet 192.168.1.1" & System.Environment.NewLine) TextBox1.Text = sOut.ReadToEnd System.Windows.Forms.Application.DoEvents() If (sOut.ReadToEnd).Contains("login:") Then sIn.Write("root" & System.Environment.NewLine) End If TextBox1.Text = sOut.ReadToEnd System.Windows.Forms.Application.DoEvents() If (sOut.ReadToEnd).Contains("Password:") Then sIn.Write("1234" & System.Environment.NewLine) End If TextBox1.Text = sOut.ReadToEnd System.Windows.Forms.Application.DoEvents() If (sOut.ReadToEnd).Contains("You are not allowed to log in in the next 15 seconds") Then MessageBox.Show("La connexion à échouée !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error) End If TextBox1.Text = sOut.ReadToEnd System.Windows.Forms.Application.DoEvents() If Not myProcess.HasExited Then myProcess.Kill() MessageBox.Show("La connexion est terminée.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) End If 'sIn.Write("exit" & System.Environment.NewLine) sIn.Close() sOut.Close() sErr.Close() myProcess.Close()
Merci par avance pour votre générosité intellectuelle
Partager