1个回答
2013-08-28
展开全部
'请试看这个 添加 Command1 修改下面你要检测的IP地址
Private Sub Command1_Click()
MsgBox IIf(CheckServ("192.168.1.1"), "服务器联线中", "服务器未联线") '你的服务器IP地址
End Sub
Public Function CheckServ(Ipadr As String) As Boolean
Dim aa$, bb$, fname$
CheckServ = False
fname = "c:\tmpfile.txt"
Open "c:\testip.bat" For Output As #1
Print #1, "@echo off"
Print #1, "ping " & Ipadr & " > " & fname
Close #1
If Dir(fname) <> "" Then Kill fname
Call Shell("cmd /c " & "c:\testip.bat", vbHide)
'延时5秒内是否得到文档
starttm = Timer
Do
DoEvents
If Dir(fname) <> "" Then
If FileLen(fname) > 10 Then Exit Do '得到文档即退出检测
End If
Loop Until Timer > = starttm + 5
bb = ""
If Dir(fname) <> "" Then
Open fname For Input As #1
While Not EOF(1)
Line Input #1, aa
bb = bb & aa & vbCrLf
Wend
Close #1
End If
CheckServ = IIf(InStr(bb, "Request") > 0, False, True)
If Dir("c:\testip.bat") <> "" Then Kill "c:\testip.bat"
End Function
Private Sub Command1_Click()
MsgBox IIf(CheckServ("192.168.1.1"), "服务器联线中", "服务器未联线") '你的服务器IP地址
End Sub
Public Function CheckServ(Ipadr As String) As Boolean
Dim aa$, bb$, fname$
CheckServ = False
fname = "c:\tmpfile.txt"
Open "c:\testip.bat" For Output As #1
Print #1, "@echo off"
Print #1, "ping " & Ipadr & " > " & fname
Close #1
If Dir(fname) <> "" Then Kill fname
Call Shell("cmd /c " & "c:\testip.bat", vbHide)
'延时5秒内是否得到文档
starttm = Timer
Do
DoEvents
If Dir(fname) <> "" Then
If FileLen(fname) > 10 Then Exit Do '得到文档即退出检测
End If
Loop Until Timer > = starttm + 5
bb = ""
If Dir(fname) <> "" Then
Open fname For Input As #1
While Not EOF(1)
Line Input #1, aa
bb = bb & aa & vbCrLf
Wend
Close #1
End If
CheckServ = IIf(InStr(bb, "Request") > 0, False, True)
If Dir("c:\testip.bat") <> "" Then Kill "c:\testip.bat"
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询