Author |
Message |
MNJ(m-studio)

|
Posted: Visual Basic General, ping IP/host |
Top |
hey
i have now somewhat succesfully made an ip-tracker.
how do i make it able to "ping" an IP og host sa it will send out 4 packets or something and then count how many returns you know what i mean im sure.
and is it possible to get a "whois" thing build in to it
im using Visual Basic xpress 2005.
//Martin
Visual Basic8
|
|
|
|
 |
DMan1

|
Posted: Visual Basic General, ping IP/host |
Top |
|
|
 |
alien-

|
Posted: Visual Basic General, ping IP/host |
Top |
Hope this helps (From VB101 Samples):
Private Sub DoPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DoPing.Click
' ping the IP address provided.
' This call blocks until the ping is successful or
' the timeout expires
If Me.pingIPAddress.Text.Length > 0 Then
Me.DoPing.Enabled = Me.doPingAsynch.Enabled = False
Try
Dim reply As PingReply = ping.Send(Me.pingIPAddress.Text)
'Show the ping results
ShowPingResultInfo(reply)
Catch ex As PingException
MessageBox.Show( "The following error occured:" & Microsoft.VisualBasic.Chr(10) & "" & Microsoft.VisualBasic.Chr(13) & "" + ex.Message, "Network Sample", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Me.DoPing.Enabled = Me.doPingAsynch.Enabled = True
Else
MessageBox.Show( "You must enter an address to ping first", "Network Sample", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Private Sub ShowPingResultInfo(ByVal reply As PingReply)
' Show the details of the PingReply
If reply.Status = IPStatus.Success Then
Dim builder As StringBuilder = New StringBuilder
builder.Append( "You pinged: " & Microsoft.VisualBasic.Chr(9) & "" & Microsoft.VisualBasic.Chr(9) & "")
builder.AppendLine(reply.Address.ToString)
builder.AppendLine()
builder.Append( "The status returned was: " & Microsoft.VisualBasic.Chr(9) & "")
builder.AppendLine(reply.Status.ToString)
builder.AppendLine()
builder.Append( "The roundtrip time was: " & Microsoft.VisualBasic.Chr(9) & "")
builder.AppendLine(reply.RoundtripTime.ToString( "N"))
builder.AppendLine()
If Not (reply.Buffer Is Nothing) Then
builder.Append( "The reply message was: " & Microsoft.VisualBasic.Chr(9) & "")
builder.AppendLine(ConvertByteBufferToString(reply.Buffer))
builder.AppendLine()
End If
Dim options As PingOptions = reply.Options
builder.Append( "Ttl: " & Microsoft.VisualBasic.Chr(9) & "" & Microsoft.VisualBasic.Chr(9) & "" & Microsoft.VisualBasic.Chr(9) & "")
builder.AppendLine(options.Ttl.ToString)
builder.AppendLine()
builder.Append( "Dont Fragment: " & Microsoft.VisualBasic.Chr(9) & "" & Microsoft.VisualBasic.Chr(9) & "")
builder.AppendLine(options.DontFragment.ToString)
builder.AppendLine()
MessageBox.Show(builder.ToString, "Ping Results", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
MessageBox.Show( "Ping was not Successfull." & Microsoft.VisualBasic.Chr(10) & "" & Microsoft.VisualBasic.Chr(13) & "Status Code: " + reply.Status.ToString, "Ping Results", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
|
|
|
|
 |
ReneeC

|
Posted: Visual Basic General, ping IP/host |
Top |
Wow that looks unbelievably laborious....
|
|
|
|
 |
Simao

|
Posted: Visual Basic General, ping IP/host |
Top |
Try this
My .Computer.Network.Ping("www.google.com")
Simao
landsimao.hotmail.com
|
|
|
|
 |
M-Studios

|
Posted: Visual Basic General, ping IP/host |
Top |
simao - how do i make the computer write it sa the user can se it
it have to write the ip an domain it pinged.
the ping rate
how manu packets send, hoe many lost etc.
can you do that
|
|
|
|
 |
spotty

|
Posted: Visual Basic General, ping IP/host |
Top |
http://msdn2.microsoft.com/en-us/library/he5sca5t.aspx
this just returns a true or false if successful - if you want more details then you would need to use one of the alternatives.
you could simply as an alternative process.start an external ping.exe and capture the output.
|
|
|
|
 |
M-Studios

|
Posted: Visual Basic General, ping IP/host |
Top |
Spotty - how do you do that
im novice in programming. sa please help me a little more.
//Martin
|
|
|
|
 |
spotty

|
Posted: Visual Basic General, ping IP/host |
Top |
Some code to capture the output from a command shell application like ping. In this case you are executing a command Ping.exe 1.1.2.3 and will get the return the output from this command as a string.
This would work if you already have command shell applications that you want to run and get the output from.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As String = RunExecutable("Ping.exe", "1.1.2.3") MsgBox(s) End Sub
Public Shared Function RunExecutable(ByVal ExecutableName As String, ByVal args As String) As String Dim p As Diagnostics.Process = New Diagnostics.Process p.StartInfo.FileName = ExecutableName p.StartInfo.Arguments = args p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardOutput = True p.Start() Return p.StandardOutput.ReadToEnd p.WaitForExit() End Function
End Class
|
|
|
|
 |
M-Studios

|
Posted: Visual Basic General, ping IP/host |
Top |
hey.
finaly working.
but do you know how to make it close the damn console wondow that appears
and can you make it write the result in a richtextbox
i have tried changing it myself, but it wont work
//Martin
|
|
|
|
 |
spotty

|
Posted: Visual Basic General, ping IP/host |
Top |
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
may help to not show the window
It writes a string - so just set the text property of the textbox or whatever control you want to use.
|
|
|
|
 |
M-Studios

|
Posted: Visual Basic General, ping IP/host |
Top |
the string is very difficuilt to red, ther4e is no "next lines" sa it is just out in one, not like in the msgbox.
is it possible to fix that
|
|
|
|
 |
spotty

|
Posted: Visual Basic General, ping IP/host |
Top |
If your trying to display it in a textbox - set the textbox multiline property to true and it will display in exactly the same way as the messagebox contents.
|
|
|
|
 |
M-Studios

|
Posted: Visual Basic General, ping IP/host |
Top |
WOW!
that did the trick, i used a Rich Textbox berfore.
now another question. is it possible to show the ping progress in an progressbar
and:
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
does not work ): it still shows the black prompt window ):
//Martin
|
|
|
|
 |
spotty

|
Posted: Visual Basic General, ping IP/host |
Top |
No
The process is purely a call to an external process. You cant update a progress bar from here. This will result in the window not showing.
Public Shared Function RunExecutable(ByVal ExecutableName As String, ByVal args As String) As String Dim p As Diagnostics.Process = New Diagnostics.Process p.StartInfo.FileName = ExecutableName p.StartInfo.Arguments = args p.StartInfo.UseShellExecute = False p.StartInfo.CreateNoWindow = True
p.StartInfo.RedirectStandardOutput = True p.Start() Return p.StandardOutput.ReadToEnd p.WaitForExit() End Function
|
|
|
|
 |
|