在Win2000系统中,可以通过Wscript.Shell对象的Exec方法执行命令,
简单的代码如下:
1 Response.Buffer = true
1
2url = " www.topronet.com "
3
4Set objWShell = CreateObject("WScript.Shell")
5Set objCmd = objWShell.Exec("ping " & url)
6strPResult = objCmd.StdOut.Readall()
7set objCmd = nothing: Set objWShell = nothing
8
9strStatus = "离线"
10if InStr(strPResult,"TTL=")>0 then strStatus = "在线"
11
12response.write url & " 状态为: " & strStatus
13response.write ".
<br/>
1" & replace(strPResult,vbCrLf,"
<br/>
1")
2response.write "
<br/>
<hr/>
1慈勤强编写,欢迎访问
<a href="http://blog.csdn.net/cqq" target="_blank">http://blog.csdn.net/cqq</a>
1"
在XP系统或者Windows.NET Server系统中,可以使用WMI来实现,
代码如下:
1
2url = " www.topronet.com "
3
4WMI = "winmgmts:{impersonationLevel=impersonate}"
5
6wqlQuery = "SELECT StatusCode FROM Win32_PingStatus WHERE Address" & _
7" = '" & url & "'"
8
9set PingResult = GetObject(WMI).ExecQuery(wqlQuery, "WQL", 48)
10
11
12Response.write url & " 状态 "
13For Each result in PingResult
14if clng(result.StatusCode)>0 then
15response.write "离线"
16else
17response.write "在线"
18end if
19Next
当然,我们也可以自己编写相应的组件或者使用一些现成的组件来实现这样的功能,
这里就不多说了。