วันเสาร์ที่ 9 เมษายน พ.ศ. 2554

การทำโปรแกรม ปิง (Ping)

Public Class PingCheck_V2
Dim tmp(10) As String

Private Sub PingCheck_V2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
string_ip()
Button1.Enabled = False
Button2.Enabled = True
timer_data()
End Sub
Private Sub string_ip()
tmp(1) = "xx.xx.xx.xx"
tmp(2) = "
"xx.xx.xx.xx"
tmp(3) = "
"xx.xx.xx.xx"
tmp(4) = "209.85.175.147" 'Google
tmp(5) =
"xx.xx.xx.xx"
tmp(6) =
"xx.xx.xx.xx"
tmp(7) =
"xx.xx.xx.xx"
tmp(8) =
"xx.xx.xx.xx"
tmp(9) =
"xx.xx.xx.xx"
tmp(10) =
"xx.xx.xx.xx"
End Sub
Private Sub check_ip(ByVal string_ip As String, ByVal tag_name As Integer)
If My.Computer.Network.Ping(string_ip) Then
alert_string(tag_name, Color.Green)
Else
alert_string(tag_name, Color.Red)
End If
End Sub
Private Sub alert_string(ByVal tag_name As Integer, ByVal string_color As Color)

For Each object_label As Object In Me.Controls
If TypeOf object_label Is Label Then
If CType(object_label, Label).Tag = tag_name Then
If string_color = Color.Red Then
CType(object_label, Label).ForeColor = Color.Red
Else
CType(object_label, Label).ForeColor = Color.Green
End If
End If
End If
Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = True
PictureBox1.Image = ProPing.My.Resources.Resources.sonic
ProgressBar1.Value = 30
timer_data()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Enabled = True
Button2.Enabled = False
PictureBox1.Image = ProPing.My.Resources.Resources.sonicwarp
ProgressBar1.Value = 0
Timer1.Stop()
Timer2.Stop()
Label1.ForeColor = Color.Orange
Label2.ForeColor = Color.Orange
Label3.ForeColor = Color.Orange
Label4.ForeColor = Color.Orange
Label5.ForeColor = Color.Orange
Label6.ForeColor = Color.Orange
Label7.ForeColor = Color.Orange
Label8.ForeColor = Color.Orange
Label9.ForeColor = Color.Orange
Label10.ForeColor = Color.Orange
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Time_Count.Text = Time_Count.Text - 1
ProgressBar1.Value = Time_Count.Text
If Time_Count.Text = "0" Then
Time_Count.Text = "30"
timer_data()
End If
End Sub
Private Sub timer_data()

Timer1.Interval = 30000 '1000 = 1 วินาที
Timer1.Enabled = True
Timer2.Interval = 1000 '1000 = 1 วินาที
Timer2.Enabled = True
Time_Count.Text = "30" 'Now.Second
Timer1.Start()
Timer2.Start()
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 30
For i As Integer = 1 To 10
check_ip(tmp(i), i)
Next

End Sub
End Class

ไม่มีความคิดเห็น:

แสดงความคิดเห็น