Tracert In VB.NET 2008

W

whitethomas12

Hi,

I am kind of stuck on a project and I need some help with creating a
VB.NET (Visual Studios 2008) application to do traceroute. I have
looked all over the web and I cannot find anything really useful.

Can some one please post some sample code so I can view it. Once I
have an I dea of how to do it then I can simply add it to the rest of
my code.

Thank you for all of your help
 
L

Lloyd Sheen

Hi,

I am kind of stuck on a project and I need some help with creating a
VB.NET (Visual Studios 2008) application to do traceroute. I have
looked all over the web and I cannot find anything really useful.

Can some one please post some sample code so I can view it. Once I
have an I dea of how to do it then I can simply add it to the rest of
my code.

Thank you for all of your help

If you want to replicate tracert then I can be of no help. But if you can
use the exe that comes with windows, what you want to investigate are:

Process class - this will allow you to start execution of the tracert exe
Within this you will want to look into the ProcessInfo class which will
allow you to input the parameters.
And you will want to check out the redirection of the stout information
from the process.

You will execute the process and then (sorry not close to VS right now) a
waitforexit on the process to allow it to execute till the end. There are
settings such that it can execute without a cmd window.

You can then take the stdout and present it in a GUI if you want.

Hope this helps
LS
 
W

whitethomas12

If you want to replicate tracert then I can be of no help.  But if you can
use the exe that comes with windows, what you want to investigate are:

Process class - this will allow you to start execution of the tracert exe
    Within this you will want to look into the ProcessInfo class whichwill
allow you to input the parameters.
    And you will want to check out the redirection of the stout information
from the process.

You will execute the process and then (sorry not close to VS right now) a
waitforexit on the process to allow it to execute till the end.  There are
settings such that it can execute without a cmd window.

You can then take the stdout and present it in a GUI if you want.

Hope this helps
LS

I currently created a simple example using the tracert.exe file in the
windows\system32 folder, but the only issue that I have is that the
application that I created opens the command prompt and then closes
it. Basically what I would like to do is have this application run in
the back ground and send me emails based on route a route change (I
just implemented a failover system for our remote site). The following
is my code (found an example is C# in google groups)

Imports System
Imports System.Net
Imports System.Net.Sockets

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim p As New Process()
Dim pInfo As New ProcessStartInfo()
pinfo.UseShellExecute = False
pInfo.RedirectStandardOutput = True
pInfo.Arguments = "192.168.4.253"
pInfo.WorkingDirectory = "C:\windows\system32"
'this for nt* computers
pInfo.FileName = "tracert"
p.StartInfo = pInfo
p.Start()
Dim sr As System.IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read()
While input <> -1
sb.Append(CChar(ChrW(input)))


input = sr.Read()
End While


MessageBox.Show(sb.ToString())
End Sub
End Class
 
W

whitethomas12

I currently created a simple example using the tracert.exe file in the
windows\system32 folder, but the only issue that I have is that the
application that I created opens the command prompt and then closes
it.  Basically what I would like to do is have this application run in
the back ground and send me emails based on route a route change (I
just implemented a failover system for our remote site). The following
is my code (found an example is C# in google groups)

Imports System
Imports System.Net
Imports System.Net.Sockets

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
        Dim p As New Process()
        Dim pInfo As New ProcessStartInfo()
        pinfo.UseShellExecute = False
        pInfo.RedirectStandardOutput = True
        pInfo.Arguments = "192.168.4.253"
        pInfo.WorkingDirectory = "C:\windows\system32"
        'this for nt* computers
        pInfo.FileName = "tracert"
        p.StartInfo = pInfo
        p.Start()
        Dim sr As System.IO.StreamReader = p.StandardOutput
        Dim sb As New System.Text.StringBuilder("")
        Dim input As Integer = sr.Read()
        While input <> -1
            sb.Append(CChar(ChrW(input)))

            input = sr.Read()
        End While

        MessageBox.Show(sb.ToString())
    End Sub
End Class- Hide quoted text -

- Show quoted text

How can I have it work without having the command prompt open
 
L

Lloyd Sheen

I currently created a simple example using the tracert.exe file in the
windows\system32 folder, but the only issue that I have is that the
application that I created opens the command prompt and then closes
it. Basically what I would like to do is have this application run in
the back ground and send me emails based on route a route change (I
just implemented a failover system for our remote site). The following
is my code (found an example is C# in google groups)

Imports System
Imports System.Net
Imports System.Net.Sockets

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim p As New Process()
Dim pInfo As New ProcessStartInfo()
pinfo.UseShellExecute = False
pInfo.RedirectStandardOutput = True
pInfo.Arguments = "192.168.4.253"
pInfo.WorkingDirectory = "C:\windows\system32"
'this for nt* computers
pInfo.FileName = "tracert"
p.StartInfo = pInfo
p.Start()
Dim sr As System.IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read()
While input <> -1
sb.Append(CChar(ChrW(input)))

input = sr.Read()
End While

MessageBox.Show(sb.ToString())
End Sub
End Class- Hide quoted text -

- Show quoted text

How can I have it work without having the command prompt open

use pInfo.WindowStyle = ProcessWindowStyle.Hidden and you will not see the
cmd window.

LS
 
W

whitethomas12

How can I have it work without having the command prompt open

use pInfo.WindowStyle = ProcessWindowStyle.Hidden and you will not see the
cmd window.

LS- Hide quoted text -

- Show quoted text -

Thank you for all of your help
 
W

whitethomas12

How can I have it work without having the command prompt open

use pInfo.WindowStyle = ProcessWindowStyle.Hidden and you will not see the
cmd window.

LS- Hide quoted text -

- Show quoted text -

I just tried it and the window still appears. I am not sure what I am
doing wrong on that one
 
A

AMercer

The part below can be simplified:
p.Start()
Dim sr As System.IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read()
While input <> -1
sb.Append(CChar(ChrW(input)))
input = sr.Read()
End While

p.start
dim s as string = p.StandardOutput.ReadToEnd()
p.WaitForExit()

This looks goofy (read before wait), but it avoids a documented deadlock, see:

http://msdn2.microsoft.com/en-us/li...sstartinfo.redirectstandardoutput(VS.80).aspx
 
A

AMercer

I just tried it and the window still appears. I am not sure what I am
doing wrong on that one

My function for doing this is below:

Public Shared Function ShellQuiet(ByVal ExeFileName As String, Optional
ByVal Arguments As String = "") As String
' run an exe file quietly (no cmd window) with command args, wait for
completion, return stdout string
' if an error occurs, return exception info
Dim s As String
Dim p As New Process
With p.StartInfo
.FileName = ExeFileName
.Arguments = Arguments
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
End With
Try
p.Start()
s = p.StandardOutput.ReadToEnd() ' to avoid a documented deadlock, do
this first ...
p.WaitForExit() ' ... and do this second - looks goofy, but it is good
code
Catch ex As Exception
s = ExceptionString(ex)
End Try
p.Dispose()
Return s
End Function
 
A

AMercer

s = ExceptionString(ex)

ExceptionString is ex.ToString with with inner exceptions appended.
 
G

Guest

(e-mail address removed) wrote in (e-mail address removed):
Hi,

I am kind of stuck on a project and I need some help with creating a
VB.NET (Visual Studios 2008) application to do traceroute. I have
looked all over the web and I cannot find anything really useful.

Can some one please post some sample code so I can view it. Once I
have an I dea of how to do it then I can simply add it to the rest of
my code.

I believe IPWorks has a tracert component

Check IndyProject, may have one too.

Or like others have suggested, run tracert, and parse the output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top