如何测试本机是否连网?
3 posters
第二问如何测试本机是否连网?答案征集9.10
彭威- 帖子数 : 48
注册日期 : 12-09-06
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Command1.Move (Me.Width - Command1.Width) \ 2, (Me.Height - Command1.Height) \ 2
End Sub
Private Sub Command1_Click()
Dim linkyn As Boolean
fname = App.Path & "\test.bat"
Open fname For Output As #1
Print #1, "ping 192.168.1.1 -n 1 > c:\pingtest.txt"
Close #1
DoEvents
Shell fname, vbHide
Sleep 2000 '延长时间2秒,等待test.bat的结果
linkyn = False
Open "c:\pingtest.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, x
If InStr(x, "Reply from") > 0 Then
n = InStr(x, ": ")
Gateway = Mid(x, n + 1)
MsgBox "连接网络成功" & Chr(13) & "以下是ping的资料" & Chr(13) & Gateway
linkyn = True
Exit Do
End If
Loop
Close #1
If linkyn = False Then
MsgBox "无法联线成功"
End If
Kill fname
Kill "c:\pingtest.txt"
End Sub
Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Command1.Move (Me.Width - Command1.Width) \ 2, (Me.Height - Command1.Height) \ 2
End Sub
Private Sub Command1_Click()
Dim linkyn As Boolean
fname = App.Path & "\test.bat"
Open fname For Output As #1
Print #1, "ping 192.168.1.1 -n 1 > c:\pingtest.txt"
Close #1
DoEvents
Shell fname, vbHide
Sleep 2000 '延长时间2秒,等待test.bat的结果
linkyn = False
Open "c:\pingtest.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, x
If InStr(x, "Reply from") > 0 Then
n = InStr(x, ": ")
Gateway = Mid(x, n + 1)
MsgBox "连接网络成功" & Chr(13) & "以下是ping的资料" & Chr(13) & Gateway
linkyn = True
Exit Do
End If
Loop
Close #1
If linkyn = False Then
MsgBox "无法联线成功"
End If
Kill fname
Kill "c:\pingtest.txt"
End Sub
雷兵兵- 帖子数 : 50
注册日期 : 12-09-05
年龄 : 32
地点 : 黄石职业技术学院
彭威 写道:Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Command1.Move (Me.Width - Command1.Width) \ 2, (Me.Height - Command1.Height) \ 2
End Sub
Private Sub Command1_Click()
Dim linkyn As Boolean
fname = App.Path & "\test.bat"
Open fname For Output As #1
Print #1, "ping 192.168.1.1 -n 1 > c:\pingtest.txt"
Close #1
DoEvents
Shell fname, vbHide
Sleep 2000 '延长时间2秒,等待test.bat的结果
这是什么东西?? 豆豆哥能解释下么?
linkyn = False
Open "c:\pingtest.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, x
If InStr(x, "Reply from") > 0 Then
n = InStr(x, ": ")
Gateway = Mid(x, n + 1)
MsgBox "连接网络成功" & Chr(13) & "以下是ping的资料" & Chr(13) & Gateway
linkyn = True
Exit Do
End If
Loop
Close #1
If linkyn = False Then
MsgBox "无法联线成功"
End If
Kill fname
Kill "c:\pingtest.txt"
End Sub