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
| Imports System.Net.NetworkInformation
Imports System.Threading
Imports System.Text
Public Class pinger
Private Sub Listbox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles Listbox1.DrawItem
Dim BackColor As Color = If(DirectCast(Listbox1.Items(e.Index), String).Contains("Connecté"), Color.Green, If(DirectCast(Listbox1.Items(e.Index), String).Contains("Déconnecté"), Color.Red, Color.Red))
e.Graphics.FillRectangle(New SolidBrush(BackColor), e.Bounds)
e.Graphics.DrawString(DirectCast(Listbox1.Items(e.Index), String), Listbox1.Font, New SolidBrush(Listbox1.ForeColor), e.Bounds.Left + 1, e.Bounds.Top + 1)
End Sub
Private Sub NsButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NsButton1.Click
Listbox1.Items.Clear()
Dim SendPing As New Net.NetworkInformation.Ping
Dim ResponseTime As Long
' Create a buffer of 32 bytes of data to be transmitted.
Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Dim buffer As Byte() = Encoding.ASCII.GetBytes(data)
' Wait 1 second for a reply.
Dim timeout As Integer = 1000
' Set options for transmission:
' The data can go through 64 gateways or routers
' before it is destroyed, and the data packet
' cannot be fragmented.
Dim options As New PingOptions(64, True)
Dim Result As Net.NetworkInformation.PingReply
Dim serveurs As New List(Of String)()
serveurs.Add("10.252.0.29")
serveurs.Add("10.252.0.38")
serveurs.Add("10.252.0.39")
serveurs.Add("10.252.0.41")
Try
If NsProgressBar1.Value = NsProgressBar1.Maximum Then
End If
NsProgressBar1.Minimum = 0
NsProgressBar1.Maximum = 100
Dim i As Integer
For i = 0 To 100
NsProgressBar1.Value = i
Application.DoEvents()
System.Threading.Thread.Sleep(25)
Label164.Text = NsProgressBar1.Value.ToString() + "%"
Next
For Each serveur As String In serveurs
Result = SendPing.Send(serveur, timeout, buffer, options)
ResponseTime = Result.RoundtripTime
If Result.Status = Net.NetworkInformation.IPStatus.Success Then
Listbox1.Items.Add("Connecté " & ResponseTime.ToString & "ms")
Else
Listbox1.Items.Add("Déconnecté")
End If
Next
Catch ex As Exception
End Try
End Sub
End Class |
Partager