vb调用ping命令检测网络
添加一个textbox控件 代码如下:运行即可得到目的
Public Function CmdPing(ByVal strIp As String) As String
Dim p As New Process '创建一个线程
***.s断率事报tartInfo.FileNa来自me = "cmd.exe"
***.startInfo.UseShellExecute = False
***.sta360问答rtInfo.Redire盾输关乡载双希各ctStandardInput = True
***.startInfo.RedirectStanda式组么析rdOutput = True
***.startI突怕约nfo.Redir地抗于商刘获力报ectStandardError = True
***.startInfo.CreateNoWindow = Tru极古属e
Dim pingrst As String
***.start()
p.***.writeline("ping -n 1 " + strIp)
p.***.writeline("exit")
Dim strRst As String = p.***.readtoend()
If (***.indexof("(0% loss)") <> -1) Then
pingrst = "连接成功"
ElseIf (***.indexof("Destination host unreachable.") <> -1) Then
pingrst = "无法到达目的主机"
ElseIf ((***.indexof("Request timed out.") <> -1) Or (***.indexof("(100% loss)") <> -1)) Then
pingrst = "超训热吸时"
ElseIf (***.indexof("Unknown host") <> -1) Then
pingrst = "无法解析主机"
E食员协吧两一环lse
pingrst = strRst
End If
***.close()
Return pingrst
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As ***.eventargs) Handles ***.load
Dim ip As String = ""
D项难做固队氧若右神负滑im strRst As S进轮布响tring = CmdPin例层波食州娘伟g(ip)
***.text = strRst
End Sub
爱资源吧版权声明:以上文中内容来自网络,如有侵权请联系删除,谢谢。