Capture telnet output

nakib

Newcomer
Joined
Feb 9, 2008
Messages
2
Hi,

I'm making a program that traces urls/IPs and show the results graphically.

The problem is...
I need to make a traceroute from a router, so i have to telnet the router. once in the router, i need to type the username and the password..
then, i have to execute the command traceroute ("www.google.com" i.e.)..

All these in command-line...

Code:
Public Class Telnet

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myProcess As Process = New Process()
        Dim s As String
        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 router-ext" & System.Environment.NewLine) '1*
        sIn.Write("exit" & System.Environment.NewLine)
        s = sOut.ReadToEnd()                                                     '2*---AT THIS POINT, s AS THE VALUE ""
        If (sOut.ReadToEnd).Contains("WELCOME TO  ROUTER-EXT") Then
            sIn.Write("<here i put the username>" & System.Environment.NewLine)
            sIn.Write("<here i put the password>" & System.Environment.NewLine)
            sIn.Write("traceroute" + TextBox2.Text & System.Environment.NewLine)
            TextBox1.Text = sOut.ReadToEnd
        Else
            MsgBox("Cant't connect ROUTER-EXT! Check your connection!", MsgBoxStyle.Information, "Error")
        End If
        If Not myProcess.HasExited Then
            myProcess.Kill()
        End If
        sIn.Close()
        sOut.Close()
        sErr.Close()
        myProcess.Close()
    End Sub
End Class

At 2*, with these code i have nothing at s variable...
At 1*, if i change the command "telnet router-ext" to "dir", the capture at 2* will be...

Code:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Andre Silva\My Documents\Universidade\2007-2008\CpC\Nova pasta\Teste\Teste\bin\Debug>dir
 Volume in drive C is ze carlos
 Volume Serial Number is 5499-E336

 Directory of C:\Documents and Settings\Andre Silva\My Documents\Universidade\2007-2008\CpC\Nova pasta\Teste\Teste\bin\Debug

03-03-2008  12:58    <DIR>          .
03-03-2008  12:58    <DIR>          ..
03-03-2008  01:27               109 historyTG.txt
29-02-2008  17:53               154 historyUM.txt
03-01-2008  11:46           192.512 Jscape.Telnet.dll
28-01-2008  14:41             1.486 Readme.txt
21-07-2007  01:33               490 Teste.vshost.exe.manifest
03-03-2008  12:58         3.847.168 VisualTraceroute.exe
03-03-2008  12:58           171.520 VisualTraceroute.pdb
03-03-2008  12:58            14.328 VisualTraceroute.vshost.exe
24-01-2008  17:20             1.498 VisualTraceroute.vshost.exe.manifest
03-03-2008  12:58               696 VisualTraceroute.xml
              10 File(s)      4.229.961 bytes
               2 Dir(s)   7.791.837.184 bytes free

C:\Documents and Settings\Andre Silva\My Documents\Universidade\2007-2008\CpC\Nova pasta\Teste\Teste\bin\Debug>exit

I need to capture the result of telnet command...
Any help would be welcome...

Srry for my bad english...
 
Back
Top